【问题标题】:Cannot call Bitcoin RPC from Jersey HttpClient无法从 Jersey HttpClient 调用比特币 RPC
【发布时间】: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 客户端的整个请求。

谢谢

【问题讨论】:

标签: java jersey bitcoin


【解决方案1】:

比特币 RPC 不支持分块编码请求。 由于在 0.8 之前的 Dropbox jersey 库中存在错误,因此您无法禁用它。

从 0.8 开始,您可以在配置文件中禁用它。 我不得不从 0.7 迁移到 0.8 并将其添加到我的配置文件中。

http客户端: ... chunkedEncodingEnabled: false

顺便说一下迁移概述:https://groups.google.com/forum/#!topic/dropwizard-dev/VInOW_ebiAc

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2014-11-13
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    相关资源
    最近更新 更多