有人可以告诉我在从一些 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 压缩;
- 如果不是,则在字符串中正常处理;如果,那么解压缩并获取字符串中的内容