首页 > 其他 > 详细

对包体内容进行gzip压缩

时间:2019-07-08 19:33:40      阅读:138      评论:0      收藏:0      [点我收藏+]
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压缩

原文:https://www.cnblogs.com/lxk233/p/11152971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!