开发者

IE's XMLhttpRequest's getResponseHeader("Content-Length") absent when Content-Encoded sent

Why won't IE let me see the get the Content-Length header with getResponseHeader()?

I know there the headers are being sent; I can see them with Wireshark. IE just won't let me get them.

If the Content-Encoding header is NOT sent, regardless of if the content-is gzipped or not, I can get them just fine.

Sample Code:

    function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }
    fun开发者_StackOverflowction 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.");
    }


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

That is because after unzip IE generates fake headers, according to MVP: 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜