看板 java 關於我們 聯絡資訊
※ 引述《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
Geniusking:我寫出來了,不過這個例子很有參考價值,謝謝! 04/26 11:44
runtime:雖然沒有用到 不過很好奇結果!? 05/04 02:11
Geniusking:結果就解壓縮成功啦XD 05/12 01:03