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真正支持分塊編碼或做它假呢?
謝謝