对包体内容进行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压缩的主要内容,如果未能解决你的问题,请参考以下文章