Re: [問題] Java程式如何解壓縮WebServer傳來的gzi …
※ 引述《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
推
04/26 11:44, , 1F
04/26 11:44, 1F
推
05/04 02:11, , 2F
05/04 02:11, 2F
推
05/12 01:03, , 3F
05/12 01:03, 3F
討論串 (同標題文章)