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

あなたにとって最も重要なものを含め、多くのヘッダーが欠落していることに注意してください: "Content-Encoding: deflate"

これは、MVP によると、解凍後に IE が偽のヘッダーを生成するためです 。 variable-returns-null-in-ie-11?forum=iewebdevelopment

于 2016-09-21T12:52:01.903 に答える