我正在尝试对来自 GAE 服务器的响应进行 gzip 压缩,但在内容编码中收到空值。
我有以下代码:
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/json; charset=utf-8"); //"application/json; charset=utf-8"
connection.setRequestProperty("Accept-Encoding", "gzip");
connection.setRequestProperty("User-Agent", "gzip");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//write
//read
System.out.println("Content-Encoding " + connection.getContentEncoding());
我读到在 GAE 服务器上会自动压缩。那么问题出在哪里呢?
App Engine 前端服务器依赖于许多因素,包括Accept-Encoding
and User-Agent
标头以确定是否应该压缩响应。他们这样做是因为有许多用户代理声称接受压缩响应,但实际上无法理解它们。
尝试将您的用户代理设置为合理的值(而不是“gzip”,它不是真正的用户代理),然后看看这是否有任何区别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)