Content-Length 分隔的消息正文过早结束(预期: [英] Premature end of Content-Length delimited message body (expected:

查看:72
本文介绍了Content-Length 分隔的消息正文过早结束(预期:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get HTTP response with the help of apache httpclient. I get headers successfully but it throws exception when I try to get contents. Exception is:

 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)

我的代码是:

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);

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

any help will be appreciated. thanks

推荐答案

问题似乎出在服务器端,而不是您粘贴的客户端代码中.

The problem appears to be on the server-side, not in the client code you've pasted.

服务器声称内容包含 203856 个字节,但只发送了 1070 个.

The server claimed that the content contained 203856 bytes but only sent 1070.

这篇关于Content-Length 分隔的消息正文过早结束(预期:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆