HttpGet in Android/Java with GZip encoding -


i running mvc 4 on server , save bit of data users figured enable gzip encoding, used:

(c#)  response.addheader("content-encoding", "gzip");  response.filter = new gzipstream(response.filter, compressionmode.compress); 

in android application use:

(java)  string response = ""; defaulthttpclient client = new defaulthttpclient(); httpget httpget = new httpget(url); try {     httpresponse execute = client.execute(httpget);     inputstream content = execute.getentity().getcontent();      bufferedreader buffer = new bufferedreader(         new inputstreamreader(content));     string s = "";     while ((s = buffer.readline()) != null) {         response += s;     }  } catch (exception e) {     e.printstacktrace(); } return response; 

when use gzip java code nuts out , causes gc run, never patient enough wait return.

when took off gzip server ran fine. function response returns straight away no problem.

i tried adding java code:

httpget.addheader("accept-encoding", "gzip"); 

with no success.

question is, there i'm not getting? can not put response in stream if using gzip? meant use stream , uncompress after?

what doing wrong?

instead of using

defaulthttpclient client = new defaulthttpclient(); 

you can use

contentencodinghttpclient client = new contentencodinghttpclient(); 

which subclass of defaulthttpclient , supports gzip content. need apache httpclient 4.1 this.

if have apache httpclient 4.2, should use

decompressinghttpclient client = new decompressinghttpclient(); 

if have apache httpclient 4.3, should use httpclientbuilder


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -