【发布时间】:2011-09-25 16:15:25
【问题描述】:
有人能告诉我在从一些 Http 调用获得响应时,我需要做什么才能解压缩 GZIP 内容。
要使用 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??`$?@??????....
如果我能实现以下内容就好了:
- 能够检测内容是否经过 GZIP 压缩;
- 如果不是,则在字符串中正常处理;如果,那么解压缩并获取字符串中的内容
【问题讨论】:
-
对于 Jersey 2.0,请参阅 stackoverflow.com/questions/17834028/…
标签: java jersey gzip jersey-1.0