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

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

2015-07-31 10:42 591 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: