现在常用的浏览器也都支持gzip。所以用HttpClient来构造HTTP请求,在数据路转化成字符串之前最好先进行判断是否是压缩格式。
Http-component判断方式和处理方式如下:
private DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(final HttpResponse response, final HttpContext context) throws HttpException,
IOException {
HttpEntity entity = response.getEntity();
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
for (HeaderElement element : ceheader.getElements()) {
if (element.getName().equalsIgnoreCase("gzip")) {
response.setEntity(new GzipDecompressingEntity(response.getEntity()));
return;
}
Note:Http-component的版本要足够高,否则是找不到GzipDecompressingEntity的