I've a HTTP communication to a webserver requesting JSON data. I'd like compress this data stream with Content-Encoding: gzip
. Is there a way I can set Accept-Encoding: gzip
in my HttpClient? The search for gzip
in the Android References doesn't show up anything related to HTTP, as you can see here.
相关问题
- Angular RxJS mergeMap types
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
I think the sample of code at this link is more interesting: ClientGZipContentCompression.java
They are using HttpRequestInterceptor and HttpResponseInterceptor
Sample for request:
Sample for answer:
In my case it was like this:
I haven't used GZip, but I would assume that you should use the input stream from your
HttpURLConnection
orHttpResponse
asGZIPInputStream
, and not some specific other class.If you're using API level 8 or above there's AndroidHttpClient.
It has helper methods like:
and
leading to much more succinct code:
You should use http headers to indicate a connection can accept gzip encoded data, e.g:
Check response for content encoding: