try {
inputStream = connection.getInputStream();
String contentEncoding = connection.getHeaderField("Content-Encoding");
if(contentEncoding != null && contentEncoding.equals("gzip")) {
inputStream = new GZIPInputStream(inputStream);
}
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
You shouldn't have to do anything. Both the Apache and HttpURLConnection clients should handle this for you (which is why you don't see code explicitly handling it in Volley).
Were you running into problems? Are you sure your server's response headers are correct?
Ficus
OK, I was looking around some more and I realized that I could use a GZIPInputStream on the NetworkResponse object's data in the parseNetworkResponse() method of a Response subclass, so that is probably a better solution than modifying the core framework and one that I am now using; however it does require about 20 more lines of code than the fix I posted above and I still think it would be nice to have the framework handle gzipped responses transparently...though probably in a more robust way than that hack I was using...joshua pierce
--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
org.json.JSONException: Value ?M?M?@?????@?DoQ"?N of type java.lang.String cannot be converted to JSONObject
It seems to me that the input stream is not correctly decompressing the gzip content and thus it can't be parsed as JSON. I can decode the NetworkResponse.data byte array myself using a GZIPInputStream in a subclass of Request<T> and it works fine. As for the server configuration, it is possible that something is wrong there, I am not responsible for configuring the server but it has gzip enabled via a php module (I think?). The headers I receive for the call that produced the above error are:
{
Vary=Accept-Encoding,
Transfer-Encoding=chunked,
Date=Mon, 29 Jul 2013 17:36:56 GMT,
Expires=Thu, 19 Nov 1981 08:52:00 GMT,
Content-Encoding=gzip,
Set-Cookie=LIMONADE0x5x0=ij1v50uid7dmtne6n45dscimo7;
path=/, Content-Type=application/json;
charset=utf-8,
Connection=keep-alive,
X-Powered-By=PHP/5.4.16,
X-Limonade=Un grand cru qui sait se faire attendre,
Server=nginx/1.4.1,
Pragma=no-cache,
Cache-Control=no-store, no-cache, must-revalidate, post-check=0, pre-check=0
}
--