有人可以告诉我在从某个Http调用获取响应时,为了解压缩GZIP内容需要做什么。解压缩GZIP http响应(使用jersey客户端api,java)
为了让我使用Jersey客户端API调用,请参见下面的代码:
String baseURI = "http://api.stackoverflow.com/1.1/answers/7539863?body=true&comments=false";
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource wr = client.resource(baseURI);
ClientResponse response = null;
response = wr.get(ClientResponse.class);
String response_data = response.getEntity(String.class);
System.out.println(response_data);
但是输出是gzip压缩的,看起来像:
{J?J??t??`[email protected]??????....
请将我好可以执行以下操作:
- 能够检测内容是否是GZIP'd;
- 如果不是,像String中的普通处理;如果,如此解压缩并获取字符串中的内容
对于泽西岛2.0请参阅http://stackoverflow.com/questions/17834028/what-is-the-jersey-2-0-equivalent-of-gzipcontentencodingfilter –