3
我有一个简单的方法来发送POST请求:Apache HttpClient(4.5)支持分块数据吗?
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()
= [内容类型:应用/ JSON,分块:真]httpPost.getEntity().getContentLength()
= -1
但远程服务器接收Content-Length
头
上请求显示实际标题有:
"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真正支持分块编码或做它假呢?
谢谢