首页 > Web开发 > 详细

使用httpclient对zip格式的响应数据解压

时间:2015-07-31 12:09:13      阅读:1472      评论:0      收藏:0      [点我收藏+]
 HttpResponse response = httpClient.execute(httpPost);
 //对zip进行解压
 response.setEntity(new GzipDecompressingEntity(response.getEntity()));//在这里特殊处理一下就行
 HttpEntity entity = response.getEntity();
 String responseXml = EntityUtils.toString(entity);//因为上面已经对zip解压。如果上面没有对zip解压,就会出现乱码

更加完善的因为还要做个判断,如果是zip格式,然后就行解压。否则不做解压处理

 HttpResponse response = httpClient.execute(httpPost);
 HttpEntity entity = response.getEntity();
if (entity.getContentEncoding().toString().equalsIgnoreCase("Content-Encoding: gzip")) {//判断是否是zip格式
     //对zip进行解压
     response.setEntity(new GzipDecompressingEntity(response.getEntity()));
     entity = response.getEntity();
}
String responseXml = EntityUtils.toString(entity);

 

使用httpclient对zip格式的响应数据解压

原文:http://www.cnblogs.com/aisam/p/4691518.html

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