Retrofit + OkHttp + GZIP-ed JSON Retrofit + OkHttp + GZIP-ed JSON json json

Retrofit + OkHttp + GZIP-ed JSON


Thanks to Jake Whartons comment it turned out the Content-Encoding: gzip header was missing. Since I told the server to add these headers, everything works fine:

<?php$data = ...;$gzdata = gzencode($data, 9, FORCE_GZIP);header('Content-Encoding: gzip');header('Content-Length: '.strlen($gzdata));... ?>


If you are downloading a gzipped file with .gz extension, you are using apache and you have mod_mime enabled.Then you can add this directive to the virtualhost or to the .htaccess file:

AddEncoding gzip .gz

In this way, when you are requesting a file with .gz extension, apache will automatically add the "Content-Encoding: gzip" header to the response (file output) and okhttp will automatically decode the response body.