虽然在 header 中添加“Accept-Encoding: gzip”预计会告诉服务器您可以接收 gxip 编码,但它似乎并未以这种方式工作。相反,服务器仅响应“Vary:Accept-Encoding”。经过很长时间的谷歌搜索,我什至无法真正找到“Vary:Accept-Encoding”的含义。为什么服务器没有按照应有的方式响应“Content-Encoding:gzip”?我错过了什么吗?
编辑:例如,在该网站上检查 www.yahoo.com (http://www.gidnetwork.com/tools/gzip-test.php) 时,它会拉入正确的 header (内容编码 header ) )。但是,当我通过 Java 代码拉入该网站时,内容编码 header 不会显示。这是为什么?
这是我用来在 Java 中打印标题的代码:
Header[] h = response.getAllHeaders();
for (int x = 0; x < h.length; x++)
System.out.println(h[x]);
最佳答案
您的服务器可能未配置为返回经过 gzip 处理的内容。
编辑:反对 http://apache.org/ ,代码按描述工作。粘贴地址为http://pastebin.com/Ajj4XBb1
关于Java:HttpResponse header 从来没有 "Content-Encoding",但确实有 "Vary: Accept-Encoding",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6207879/