ajax - IE 的 XMLhttpRequest 的 getResponseHeader ("Content-Length") 在发送 Content-Encoded 时不存在

标签 ajax internet-explorer gzip content-encoding

为什么 IE 不让我看到带有 getResponseHeader() 的获取 Content-Length header ?

我知道那里正在发送 header ;我可以用 Wireshark 看到它们。 IE 只是不会让我得到它们。

如果没有发送 Content-Encoding header ,无论内容是否被 gzip 压缩,我都可以很好地得到它们。

示例代码:

    function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }
    function handler() {
        if (oReq.readyState == 4 /* complete */) {
            if (oReq.status == 200) {
                // this alert will be missing Content-Length 
                // and Content-Encoding if Content-Encoding is sent.
                alert(oReq.getAllResponseHeaders());
            }
        }
    }

    var oReq = getXMLHttpRequest();

    if (oReq != null) {
        oReq.open("GET", "http://www.example.com/gzipped/content.js", true);
        oReq.onreadystatechange = handler;
        oReq.send();
    }
    else {
        window.alert("AJAX (XMLHTTP) not supported.");
    }

最佳答案

您可能会注意到许多标题都没有,包括对您来说最重要的:“Content-Encoding: deflate”

这是因为根据 MVP 的说法,在解压 IE 后会生成假 header :
https://social.msdn.microsoft.com/Forums/ie/en-US/b2cc04ca-1d4e-4381-9750-361128987e2f/http-response-header-variable-returns-null-in-ie-11?forum=iewebdevelopment

关于ajax - IE 的 XMLhttpRequest 的 getResponseHeader ("Content-Length") 在发送 Content-Encoded 时不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3688871/

相关文章:

php - 创建要在 wordpress 后导入中使用的 xml 文件

javascript - 学习 JavaScript 和 ajax,遇到 localhost 问题

HTML <details> 标签在 IE/Edge 中不起作用

internet-explorer - 加载时 overflow hidden 的绝对位置 div (IE7+)

java - gzip解压java的改进

node.js - Node 在 gzip 压缩后删除目录

javascript - 在点击链接上发送 $_GET 变量 - PHP 和 Ajax

javascript - 在数据库中插入值后显示成功消息

.net - WebResource.axd 不适用于 Internet Explorer 11

php - 为什么 gzip 压缩对我来说更慢?