如何使用Jersey Framework

时间:2017-01-02 19:28:51

标签: java jersey jersey-client chunked-encoding

我想要使用第三方软件工具的宁静服务 出于某种原因,我在没有Content-Length的情况下得到了响应。因此,系统将响应作为分块编码发送。出于这个原因,我的代码得到了一个破坏的json,如下所示:

1ff8\r\n{"data":...1ff8\r\nSim"[9867,"CAR\r\n1c7d\r\n...}\r\n0\r\n\r\n
// PS.:The part of '...' it was just me to not pass all data here.

所以,这些字符:1ff8\r\n; \r\n1c7d\r\n; \r\n0\r\n\r\n; ...是分块编码传输的一部分,我的应用程序收到错误:JSONException。

我使用泽西岛,我没有任何限制使用其他框架。以下是我的代码:

Client client = Client.create();
WebResource webResource = client.resource(uri);
ClientResponse response = webResource.header("X-API-Key", xApiKey)
    .header("Content-Type", "application/json; charset=UTF-8")
    .header("Accept", "application/json")
    .header("Authorization", "Bearer " + token)
    .get(ClientResponse.class);
String json = response.getEntity(String.class);
JSONObject result = new JSONObject(json);

该软件属于第三方软件工具,即使是开源软件,我也会花费大量时间来理解整个代码,或者为此创建一个插件。

0 个答案:

没有答案