相关疑难解决方法(0)

Content-Length分隔邮件正文的过早结束(预期:

我试图在apache httpclient的帮助下获得HTTP响应.我成功获得了标题但是当我尝试获取内容时它会抛出异常.例外情况是:

 org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 203856; received: 1070
        at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:180)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.fill(BufferedReader.java:154)
        at java.io.BufferedReader.readLine(BufferedReader.java:317)
        at java.io.BufferedReader.readLine(BufferedReader.java:382)
Run Code Online (Sandbox Code Playgroud)

我的代码是:

InputStream is = entity.getContent();
BufferedReader br = new BufferedReader( new InputStreamReader(is, "UTF-8"));
String line;
String str = "";
while ((line = br.readLine()) != null) {

    str = str + line + "\n";

}
log.debug(str);
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.谢谢

java apache-httpclient-4.x

14
推荐指数
2
解决办法
3万
查看次数

org.apache.http.ConnectionClosedException:块编码消息正文的提早结束:预期关闭块

我正在尝试RestAssured并写了以下语句-

String URL = "http://XXXXXXXX";
Response result = given().
            header("Authorization","Basic xxxx").
            contentType("application/json").
            when().
            get(url);
JsonPath jp = new JsonPath(result.asString());
Run Code Online (Sandbox Code Playgroud)

关于上一个声明,我收到以下异常:

org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected

我的响应中返回的标头是:

Content-Type ? application/json; qs=1 Date ? Tue, 10 Nov 2015 02:58:47 GMT Transfer-Encoding ? chunked

任何人都可以指导我解决此异常,并在缺少任何内容或任何不正确的实现时指出我。

apache http chunked-encoding rest-assured rest-assured-jsonpath

6
推荐指数
2
解决办法
2万
查看次数