HTTP compression

资料:http://www.websiteoptimization.com/speed/tweak/compress/

Http支持在传输层压缩数据,这样减少数据的传输体积,在jax-ws中,client想server发送一个请求。进行数据压缩处理,方式如下;

Map<String, List<String> httpHeaders = new HashMap<String, List<String>>(); 
httpHeaders.put("Content-Encoding", Collections.singletonList("gzip")); 
httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip")); 
Map<String, Object> reqContext = ((bindingProvider)proxy).getRequestContext(); 
requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders); 

 

 上面的代码是明确知道server能够取出压缩数据,否则会报错。如果不清楚server是否支持,可以把下面这行去掉

httpHeaders.put("Content-Encoding", Collections.singletonList("gzip"));

你可能感兴趣的:(compression)