【问题标题】:Msxml2.XMLHTTP.6.0 and HTTP 301 Moved Permanently RedirectsMsxml2.XMLHTTP.6.0 和 HTTP 301 永久移动重定向
【发布时间】:2017-04-10 10:30:11
【问题描述】:

我被告知 MsXML2 遵循重定向。但是,当访问已移动的 URL 时,我从脚本中收到“HTTP 0”错误。

我需要让它工作的原因是因为这是一个被 30 万用户使用的 Windows(侧边栏)小工具。我正在移动网站,并希望所有对旧版本的调用仍然通过。

这是简化的代码:

function MyHttpCall() {
  var httpReq = new ActiveXObject("Msxml2.XMLHTTP.6.0");
  httpReq.onreadystatechange = function() {
    if (httpReq.readyState < 4) return;
    if (httpReq.status != 200) alert("HTTP " + httpReq.status);

    alert ("Houston we have contact");
  }

  httpReq.open("GET", myURL, true);
  httpReq.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  httpReq.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
  httpReq.setRequestHeader("Pragma", "no-cache");
  httpReq.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 2008 00:00:00 GMT");
  httpReq.send();
}

我认为这与 httpReq.status != 200 有关,但我认为 readystatechange 会在状态更改后不断触发事件。为 HTTP 301 触发一个,为 HTTP 200 触发另一个。

【问题讨论】:

标签: javascript ajax xmlhttprequest msxml


【解决方案1】:

根据 Microsoft 的一篇文章,MsXML 中不允许跨域重定向。很可能就是这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-22
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    相关资源
    最近更新 更多