从Apache-httpclient提取gzip数据而不进行解压缩 [英] Extracting gzip data from Apache-httpclient without decompression

查看:471
本文介绍了从Apache-httpclient提取gzip数据而不进行解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache httpclient 4.3.5向上游服务器发送请求,该服务器返回压缩后的响应.我需要将此响应按原样传递给下游服务器,而无需进行任何形式的解压缩.但是,httpclient太有用了,它坚持解压缩响应,我找不到说服它停止的任何方法.

I'm using apache httpclient 4.3.5 to send a request to an upstream server which returns a gzipped response. I need to pass this response AS-IS to a downstream server without any form of decompression. However, httpclient is far too helpful and insists on decompressing the response and I can't find any way of persuading it to stop.

CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse serverResponse = client.execute(serverRequest);
try {
    HttpEntity entity = serverResponse.getEntity();
    downstreamResponse.setStatus(serverResponse.getStatusLine().getStatusCode());
    for (Header header : serverResponse.getAllHeaders()) {
        downstreamResponse.setHeader(header.getName(), header.getValue());
    }
    entity.writeTo(downstreamResponse.getOutputStream());
    downstreamResponse.flushBuffer();
} finally {
    serverResponse.close();
}

我确定可以使用某种形式的构造方法来配置客户端

I'm sure that there is some way of configuring the client using some form of the construct

return HttpClients.custom()
    ....
    .build();

但是我找不到它.专家可以请教吗?

but I can't find it. Can the experts please advise?

推荐答案

CloseableHttpClient client = HttpClients.custom()
        .disableContentCompression()
        .build();

这篇关于从Apache-httpclient提取gzip数据而不进行解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆