【发布时间】:2017-07-06 21:53:36
【问题描述】:
我有一个发送 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 header
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 还是伪造的?
谢谢
【问题讨论】:
标签: java apache-httpclient-4.x chunked-encoding content-length