我无法在Jersey服务中激活gzip-encoding.这就是我尝试过的:
与开始了jersey-quickstart-grizzly2从原型入门指南.
添加 rc.register(org.glassfish.grizzly.http.GZipContentEncoding.class);
(也尝试过rc.register(org.glassfish.jersey.message.GZipEncoder.class);)
开始于 mvn exec:java
经过测试 curl --compressed -v -o - http://localhost:8080/myapp/myresource
结果如下:
> GET /myapp/myresource HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 zlib/1.2.3.4 ...
> Host: localhost:8080
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Sun, 03 Nov 2013 08:07:10 GMT
< Content-Length: 7
<
* Connection #0 to host localhost left intact
* Closing connection #0
Got it!
Run Code Online (Sandbox Code Playgroud)
也就是说,尽管Accept-Encoding: deflate, …
有人可以告诉我在从某些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);
Run Code Online (Sandbox Code Playgroud)
但输出是GZIP,看起来像:
{J?J??t??`$?@??????....
Run Code Online (Sandbox Code Playgroud)
如果我能实现以下内容会很好: