我有一个简单的方法来发送 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,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是否真的支持 chunked-encoding 还是伪造它?
谢谢