Java:HttpResponse 标头永远不会有“Content-Encoding”但确实有“变化:接受编码”
虽然在标头中添加“Accept-Encoding: gzip”预计会告诉服务器您可以接收 gxip 编码,但它似乎并没有以这种方式工作。相反,服务器仅响应“Vary:Accept-Encoding”。经过很长时间的谷歌搜索,我什至无法真正找到“Vary:Accept-Encoding”的含义。为什么服务器没有按照应有的方式响应“Content-Encoding:gzip”?我错过了什么吗?
编辑:例如,在该网站上检查 www.yahoo.com (http://www.gidnetwork.com/tools/gzip-test.php) 时,它会拉入正确的标头(内容编码标头)。但是,当我通过 Java 代码拉入该网站时,内容编码标头不会显示。这是为什么?
这是我用来在 Java 中打印标题的代码:
Header[] h = response.getAllHeaders();
for (int x = 0; x < h.length; x++)
System.out.println(h[x]);
I'm using the following example: http://www.devdaily.com/java/jwarehouse/commons-httpclient-4.0.3/httpclient/src/examples/org/apache/http/examples/client/ClientGZipContentCompression.java.shtml
While adding "Accept-Encoding: gzip" to the headers is expected to tell the server you can receive gxip encoding back, it doesn't appear to be working that way. Instead, the servers only respond with "Vary: Accept-Encoding". After a long time of Googling, I couldn't even really find out what "Vary: Accept-Encoding" means. Why aren't the servers responding with "Content-Encoding: gzip" as they should be? Am I missing something?
EDIT: For instance, when checking www.yahoo.com on this website (http://www.gidnetwork.com/tools/gzip-test.php), it pulls in the right header (the content-encoding one). However, when I pull in that website through the Java code, the content-encoding header doesn't show up. Why is that?
Here is the code I'm using to print the headers in Java:
Header[] h = response.getAllHeaders();
for (int x = 0; x < h.length; x++)
System.out.println(h[x]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的服务器可能未配置为返回经过 gzip 压缩的内容。
编辑:针对 http://apache.org/,代码按所述工作。粘贴位于 http://pastebin.com/Ajj4XBb1
Your server is probably not configured to return gzip'ped content.
EDIT: against http://apache.org/, the code works as described. The paste is at http://pastebin.com/Ajj4XBb1