Retrofit + OkHttp + GZIP-ed JSON

戏子无情 提交于 2019-12-05 05:18:25
A2i_

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!