我是否知道如何使用"Transfer-Encoding:chunked"处理/读取响应?
目前我正在使用common-httpclient.3.1
我目前的编码如下(只能处理标题中内容长度的响应): -
httppost = new PostMethod(localurl);
httppost.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
RequestEntity entity = new StringRequestEntity(in, "application/xml", "UTF-8");
httppost.setRequestHeader("Content-length", entity.getContentLength()+"");
httppost.setRequestEntity(entity);
for (int i=0; i<retryAttempt; i++) {
try {
httpclient.executeMethod(httppost);
if (httppost.getStatusCode() == 200) {
br = new BufferedReader(new InputStreamReader(httppost.getResponseBodyAsStream(), httppost.getResponseCharSet()));
String reply = null;
long len = httppost.getResponseContentLength();
if(len != 0) {
char[] cbuf = new char[Integer.parseInt(len+"")];
if (br.read(cbuf, 0, Integer.parseInt(len+"")) != -1 ) {
repOut = String.valueOf(cbuf);
}
}else{
while ((reply = br.readLine()) != null) {
if (!reply.equals("")) …Run Code Online (Sandbox Code Playgroud)