java 用注解jsonrpc_如何在java上使用json-rpc和curl

geth --bootnodes="enode://b115ff8b97f67a6bd8294a4ea277930bf7825e755705e809442885aba85e397313e46528fb662a3828cd4356f600c10599b77822ebd192199b6e5b8cfdb530c4@127.0.0.1:30303" --networkid 15 console --datadir "private-data" --rpcport "8545" --rpc --rpccorsdomain "*" --rpcapi "eth,web3,personal" --rpcaddr 192.168.44.114

然后我在这里连接到远程计算机的区块链节点

我想在java上使用ethereum json-rpc和curl。

我把它编码成

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

public class shell{

public static void makeTran() throws Exception {

String shellcmd = "curl -X POST --data \"{\"jsonrpc\":\"2.0\",\"method\":\"personal_unlockAccount\",\"params\":[\"0xc7d863e8c89ac4b0336059b4e2cf84a57a6ba7db\", \"1\", 10],\"id\":1}\" http://192.168.44.114:8545/ -H \"Content-Type: application/json\"";

System.out.println(shellcmd);

Process process = Runtime.getRuntime().exec(shellcmd);

InputStream is = process.getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String line;

while ((line = br.readLine()) != null) {

System.out.println(line);

}

}

public static void main(String[] args) throws Exception {

makeTran();

}

}

这必须返回这行

{"jsonrpc":"2.0","id":1,"result":true}

但这个错误是

curl -X POST --data "{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["0xc7d863e8c89ac4b0336059b4e2cf84a57a6ba7db", "1", 10],"id":1}" http://192.168.44.114:8545/ -H "Content-Type: application/json"

invalid content type, only application/json is supported

这是命令

curl -X POST --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["0xc7d863e8c89ac4b0336059b4e2cf84a57a6ba7db", "1", 10],"id":1}' http://192.168.44.114:8545/ -H 'Content-Type: application/json'

如果你帮我,真的很感激!!谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值