Apache HttpClient(4.5)是否支持分块数据?

时间:2017-02-17 11:28:25

标签: java apache-httpclient-4.x chunked-encoding content-length

我有一个简单的方法来发送 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 还是伪造它?

谢谢

0 个答案:

没有答案