为什么IE不允许我看到使用getResponseHeader()
获取Content-Length标头?
我知道标题正在发送;我可以用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.");
}
答案 0 :(得分:0)
您可以注意到许多标题缺席,包括对您来说最重要的标题:"内容编码:deflate"
这是因为根据MVP,在解压缩之后IE生成假标题: 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