我有一个发送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() = Content-Type: application/json,分块: truehttpPost.getEntity().getContentLength() = -1Content-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))"
}chunked-encoding 4.5真的支持chunked-encoding吗?还是它是假的?
谢谢
发布于 2017-02-24 08:17:06
Apache HttpClient绝对支持块数据。
Httpbin.org依赖于Nginx,我想代理请求的缓冲是在它们的配置中启用的。因此,在httpbin返回的结果中看不到块传输编码。
不要使用外部服务(如httpbin.org )来检查此类标头,而是使用您自己的own服务器。
https://stackoverflow.com/questions/42296786
复制相似问题