码迷,mamicode.com
首页 > 其他好文 > 详细

对包体内容进行gzip压缩

时间:2019-07-08 19:22:48      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:def   put   cat   sum   pen   class   head   str   utf-8   

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压缩

标签:def   put   cat   sum   pen   class   head   str   utf-8   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!