Yes, for input (download) the Android implementation of HttpURLConnection
does gunzip transparently. But for output (upload) this is not done automatically. The client cannot know whether server supports compression. So you have to do it manually and you have to be sure that your servers understand the request.
You can find an example at DavidWebb.
The code to gzip the payload:
static byte[] gzip(byte[] input) {
GZIPOutputStream gzipOS = null;
try {
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
gzipOS = new GZIPOutputStream(byteArrayOS);
gzipOS.write(input);
gzipOS.flush();
gzipOS.close();
gzipOS = null;
return byteArrayOS.toByteArray();
} catch (Exception e) {
throw new WebbException(e); // <-- just a RuntimeException
} finally {
if (gzipOS != null) {
try { gzipOS.close(); } catch (Exception ignored) {}
}
}
}
And you have to set the following header:
connection.setRequestProperty("Content-Encoding", "gzip");