为什么 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.");
}