AppEngine gzip压缩 [英] AppEngine gzip compressing
问题描述
我有以下代码: $ b $
我试图从GAE服务器上gzip响应,但在Content-Encoding中收到null。 b 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);
//写入
//读取
System.out.println(Content-Encoding+ connection.getContentEncoding());
我读过GAE服务器上的压缩文件。那么可能是什么问题?App Engine前端服务器依赖于许多因素,包括<$ c $
User-Agent
标题来确定它们是否应该压缩响应。他们这样做是因为有许多用户代理声称接受gzip响应,但实际上无法理解他们。 尝试将您的用户代理设置为某种明智的(而不是'gzip',这不是真正的用户代理),看看这是否有任何区别。
I'm trying to gzip responses from GAE server, but receive null in Content-Encoding.
I have the following code:
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());
I've read that on GAE servers do compressing automatically. So what can be the problem?
The App Engine frontend servers rely on a number of factors, including the Accept-Encoding
and User-Agent
headers to determine if they should compress responses. They do this because there are a number of user agents out there that claim to accept gzipped responses, but actually can't understand them.
Try setting your user agent to something sensible (and not 'gzip', which isn't a real user agent), and see if that makes any difference.
这篇关于AppEngine gzip压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!