4

为什么 IE 不让我看到获取 Content-Length 标头getResponseHeader()

我知道正在发送标头;我可以用 Wireshark 看到它们。IE 就是不让我得到它们。

如果没有发送 Content-Encoding 标头,无论内容是否经过 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.");
    }
4

1 回答 1

0

You could note that many headers absent including most significant for you: "Content-Encoding: deflate"

那是因为解压后 IE 会生成假标题,根据 MVP: https ://social.msdn.microsoft.com/Forums/ie/en-US/b2cc04ca-1d4e-4381-9750-361128987e2f/http-response-header-变量返回 null-in-ie-11?forum=iewebdevelopment

于 2016-09-21T12:52:01.903 回答