2 renyfeng renyfeng 于 2013.07.01 16:54 提问

客户端读取服务端回执信息时出现error:org.apache.http.ConnectionClosedException

具体error: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body 。 (好像是回执信息数据太大)
网上搜了下,大概意思就是 :
本来在接管数据量,程序员显式封闭了连接(同步调用),而netty是异步处理惩罚,当连接被显式封闭后,后来的数据再次触发读写操纵时贯穿连接已经不成用。所以呈现读不一完全数据的题目。

服务端关键代码:
InputStream is = t.getRequestBody();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));

StringBuffer temp=new StringBuffer();
String lineMessage;
while ((lineMessage = reader.readLine()) != null) {
temp.append(lineMessage);
}
reader.close();
is.close();
String respXml=DuXmlDoc.execute(temp.toString());
System.out.println("!!"+respXml);
t.sendResponseHeaders(2000, respXml.length());

OutputStream os = t.getResponseBody();

os.write(respXml.getBytes());

os.flush();
os.close();

t.close();
客户端关键代码:
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
StringBuffer returnMessage = new StringBuffer();
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
String lineMessage;
while ((lineMessage = bufferedReader.readLine()) != null) {
returnMessage.append(lineMessage);
}
bufferedReader.close();
}

Csdn user default icon
上传中...
上传图片
插入图片