Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: HTTP communication should use "Accept-Encoding: gzip"

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.

like image 287
znq Avatar asked Oct 15 '09 16:10

znq


People also ask

What is accept-Encoding gzip?

The Accept-Encoding header is used for negotiating content encoding. Accept-Encoding: gzip, deflate. The server responds with the scheme used, indicated by the Content-Encoding response header. Content-Encoding: gzip. Note that the server is not obligated to use any compression method.

How do I use gzip in HTTP?

Gzip on Windows Servers (IIS Manager)Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!

What is HTTP accept-Encoding?

The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand. The server uses content negotiation to select one of the proposals and informs the client of that choice with the Content-Encoding response header.

How do I disable gzip Encoding?

In the HTTP Streamers Cupertino Settings section, click Edit. For the cupertinoUseGzipEncoding property, click the checkbox to enable the property and then click False to disable Gzip content encoding. Click Save, and then restart the application when prompted to apply the changes.


1 Answers

You should use http headers to indicate a connection can accept gzip encoded data, e.g:

HttpUriRequest request = new HttpGet(url); request.addHeader("Accept-Encoding", "gzip"); // ... httpClient.execute(request); 

Check response for content encoding:

InputStream instream = response.getEntity().getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {     instream = new GZIPInputStream(instream); } 
like image 89
Bakhtiyor Avatar answered Sep 19 '22 13:09

Bakhtiyor