标签: apache-fluent-api

GZIP 与 httpclient 4.5.3

我正在使用 httpclient 4.5.3 和 Fluent API ( http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fluent.html )。从 4.2.x 升级到 httpclient 4.5.3 后,响应中的“Content-Encoding”标头似乎从响应标头中删除,我不知道如何支持 gzip 压缩。

我正在向https://www.yahoo.com发出 GET 请求,并发送标头“Accept-Encoding”:“gzip”

我的 4.5.3 响应标头现在显示以下内容,但没有 Content-Encoding 标头:

Date: Thu, 01 Jun 2017 21:21:55 GMT
Strict-Transport-Security: max-age=2592000
X-Frame-Options: DENY
Set-Cookie: autorf=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=www.yahoo.com
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Age: 0
Transfer-Encoding: chunked
Connection: keep-alive
Via: http/1.1 ir11.fp.ne1.yahoo.com (ApacheTrafficServer)
Server: ATS
Cache-Control: no-store, no-cache, private, max-age=0
Expires: -1
Run Code Online (Sandbox Code Playgroud)

我的响应处理程序有以下代码。但是,entity.getContentEncoding() 始终为 null。

 HttpEntity entity = response.getEntity();
            Header header = entity.getContentEncoding(); …
Run Code Online (Sandbox Code Playgroud)

java gzip apache-httpclient-4.x apache-fluent-api

1
推荐指数
1
解决办法
3104
查看次数