作者qrtt1 (null)
看板java
标题Re: [问题] Java程式如何解压缩WebServer传来的gzi …
时间Mon Apr 26 08:54:57 2010
※ 引述《Geniusking (真理斯金)》之铭言:
: /* 发出HTTP request */
: HttpResponse httpResponse = new DefaultHttpClient()
: .execute(httpRequest);
: /* 若状态码为200 ok */
: if (httpResponse.getStatusLine().getStatusCode() == 200)
: {
: /* 取出回应字串 */
: String strResult = EntityUtils.toString(httpResponse.getEntity(),
: HTTP.UTF_8);
: /* 这边的strResult是被Gzip压缩过的乱码字串 */
: /* 删除多余字元 */
http://hc.apache.org/httpcomponents-client/examples.html
Custom protocol interceptors
This example shows the use of protocol interceptors to transparently modify
properties of HTTP messages sent / received by the HTTP client.
In this particular case HTTP client is made capable of transparent content
GZIP compression by adding two protocol interceptors: a request interceptor
that adds 'Accept-Encoding: gzip' header to all outgoing requests and a
response interceptor that automatically expands compressed response entities
by wrapping them with a uncompressing decorator class. The use of protocol
interceptors makes content compression completely transparent to the consumer
of the HttpClient interface.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.168.161
1F:推 Geniusking:我写出来了,不过这个例子很有参考价值,谢谢! 04/26 11:44
2F:推 runtime:虽然没有用到 不过很好奇结果!? 05/04 02:11
3F:推 Geniusking:结果就解压缩成功啦XD 05/12 01:03