首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache HttpClient (4.5)支持分块数据吗?

Apache HttpClient (4.5)支持分块数据吗?
EN

Stack Overflow用户
提问于 2017-02-17 11:28:25
回答 1查看 3.9K关注 0票数 4

我有一个发送POST请求的简单方法:

代码语言:javascript
复制
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,分块: true
  • httpPost.getEntity().getContentLength() = -1

Content-Length 但远程服务器接收报头

http://httpbin.org/post上的请求显示了实际的标题如下:

代码语言:javascript
复制
"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))"
}

chunked-encoding 4.5真的支持chunked-encoding吗?还是它是假的?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-02-24 08:17:06

Apache HttpClient绝对支持块数据。

Httpbin.org依赖于Nginx,我想代理请求的缓冲是在它们的配置中启用的。因此,在httpbin返回的结果中看不到块传输编码。

不要使用外部服务(如httpbin.org )来检查此类标头,而是使用您自己的own服务器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42296786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档