对包体内容进行gzip压缩

Posted lxk233

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对包体内容进行gzip压缩相关的知识,希望对你有一定的参考价值。

try
  HttpEntity requestEntity = new ByteArrayEntity(GzipUtil.compress(JSON.toJSONString(param),"UTF-8"));

    CloseableHttpClient client = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(url);
    httpPost.addHeader("Content-type", "application/json; charset=UTF-8");
    httpPost.setHeader("Accept", "application/json");
    httpPost.setHeader("Content-Encoding", "gzip");
    httpPost.setEntity(requestEntity);
    CloseableHttpResponse response = client.execute(httpPost);
    HttpEntity responseEntity = response.getEntity();
    String body = null;
    if (responseEntity != null)
        body = EntityUtils.toString(responseEntity,"UTF-8");
    
    EntityUtils.consume(responseEntity);
    response.close();
    return body;
catch (Exception e)
        e.printStackTrace();

 

以上是关于对包体内容进行gzip压缩的主要内容,如果未能解决你的问题,请参考以下文章

Nginx配置之Gzip压缩

开启Nginx的gzip压缩功能详解

Apache启用GZIP压缩网页传输方法

在 IIS8 中使用 Gzip 进行 Json HTTP 压缩

使用 htaccess 进行 GZIP 压缩有啥限制吗?

Azure 应用服务 - 请求中的 GZip 压缩