您的位置:首页 > 理论基础 > 计算机网络

Http请求数据GZIP压缩

2016-06-27 11:21 459 查看
可以通过Gzip对返回的数据进行压缩以减少返回数据的大小。

1、对数据压缩,并且设置response Header

         ByteArrayOutputStream out = new ByteArrayOutputStream();  

         GZIPOutputStream gout = new GZIPOutputStream(out);  

            gout.write(jsonObjectPar.toString().getBytes("UTF-8"));

            gout.close();  

         result = out.toByteArray(); 

         response.setHeader("Content-Encoding","gzip"); 
http://www.cnblogs.com/bcsflilong/p/4245336.html
2、接收端也需要进行相应处理

检测是否是通过gzip 压缩的,然后解压缩

responseString = EntityUtils.toString(new GzipDecompressingEntity(rep.getEntity()));

http://www.bubuko.com/infodetail-900261.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: