java Apache HttpClient(4.5)支持分块数据吗?
我有一个简单的方法来发送POST请求:
public HttpResponse post(InputStream content, String contentType, URI url) {
InputStreamEntity entity = new InputStreamEntity(content);
entity.setChunked(true);
entity.setContentType(contentType);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(entity)
return httpClient.execute(httpPost, httpContext);
}
httpPost似乎配置良好:
httpPost.getEntity().toString()
=[内容类型:application/json,Chunked:true]httpPost.getEntity().getContentLength()
=-1
但是远程服务器接收Content-Length
头
对http://httpbin.org/post的请求显示实际的头文件是:
"headers":{
"Accept-Encoding": "gzip,deflate",
"Content-Length": "571",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "blabla",
"Via": "1.1 localhost (Apache-HttpClient/4.5.2 (cache))"
}
=>;org.apache.http.client
4.5真的支持分块编码吗
谢谢!
# 1 楼答案
Apache HttpClient绝对支持分块数据
Httpbin。org依赖于Nginx,我猜代理请求的缓冲是在其配置中启用的。因此,在httpbin返回的结果中看不到分块传输编码
而不是使用httpbin这样的外部服务。要检查此类标题,请使用您自己的Web服务器