Java:HttpResponse 标头永远不会有“Content-Encoding”但确实有“变化:接受编码”

发布于 2024-11-10 16:35:53 字数 916 浏览 5 评论 0原文

我使用以下示例: http://www.devdaily.com/java/jwarehouse/commons-httpclient-4.0.3/httpclient/src/examples/org/apache/http/examples/client/ClientGZipContentCompression.java.shtml< /a>

虽然在标头中添加“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2024-11-17 16:35:54

您的服务器可能未配置为返回经过 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文