【发布时间】:2014-12-15 02:12:42
【问题描述】:
我正在使用 dropwizard。从资源中,我尝试通过 Jersey HttpClient 使用比特币 rpc。
使用 curl 就像一个魅力: $ curl --user user:password -X POST -d '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H '内容类型:文本/纯文本;' http://domain.name:18332/
但不知何故,从资源中使用 Jersey HTTP 客户端不起作用:
//init in run methode
final Client client = new JerseyClientBuilder(e).using(c.getJerseyClientConfiguration()).build(getName());
HTTPBasicAuthFilter httpBasicAuth = new HTTPBasicAuthFilter("user", "password");
client.addFilter(httpBasicAuth);
//From the resource
WebResource webRes = client.resource("http://domain.name:18332/");
webRes.header("content-type", "text/plain");
RPC_REQUEST rpc = new RPC_REQUEST("1.0", "curltest", "getinfo", new ArrayList<String>());
String response = webRes.post(String.class, JSONParserHelper.parseJSONToString(rpc));
JSONParserHelper.parseJSONToString(rpc) 返回以下字符串:
{"jsonrpc":"1.0","id":"curltest","method":"getinfo","params":[]}
在“webRes.post”行中导致以下错误:
! com.sun.jersey.api.client.UniformInterfaceException: Client response status: 500
编辑:使用错误的密码会导致 401。我想连接应该是正确的,问题出在其他地方。
编辑:使用 -d 而不是 --data-binary
编辑:我一回家就会转储来自 jersey http 客户端的整个请求。
谢谢
【问题讨论】:
-
刚找到有类似问题的人。今天会检查一下:stackoverflow.com/questions/25726921/…