Re: [問題] Java程式如何解壓縮WebServer傳來的gzi …

看板java作者 (null)時間15年前 (2010/04/26 08:55), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《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
結果就解壓縮成功啦XD
05/12 01:03, 3F
文章代碼(AID): #1BrEHad7 (java)
文章代碼(AID): #1BrEHad7 (java)