AJAX:一些Webkit浏览器中跨域301/302头部重定向失败

3
尝试通过302重定向从一个服务器跳转到另一个服务器,仅用于跟踪目的,我担心在苹果iOS设备和一些Webkit / Chrome浏览器上会丢失一些访问者。
HTTP/1.1 302 Moved Temporarily
Date: Tue, 26 Mar 2013 20:00:03 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.6
Expires: Tue, 03 Jul 2001 06:00:00 GMT
Last-Modified: Tue, 26 Mar 2013 20:00:03 GMT
Cache-Control: no-store
Pragma: no-cache
P3P: CP="STP CUR OUR"
x-own: 46.163.123.40
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Location: http://target2.com
Connection: close
Content-Type: text/html; charset=iso-8859-1

在Firefox和IE上,重定向是正常的。从domainA到domainA的重定向也是正常的。在Webkit/Chrome/Mobile Safari浏览器上,跨域重定向失败 :-(
javascript代码段如下:
testRedirection=function(url)
{
    var xmlhttp = null;
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();//ff,webkit
    else if (window.ActiveXObject)
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");//ie
    if(xmlhttp)
    {
        xmlhttp.open("HEAD",url,true);//tried HEAD, GET, POST
        xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState==4)
            {
                if(xmlhttp.status==200 || (xmlhttp.status>200 && xmlhttp.status<400))
                    alert("arrived with status "+xmlhttp.status);
                else
                    alert("failed with status "+xmlhttp.status);
            };
        };
        xmlhttp.send();
    };
    //\
};

无论在iPhone、iPad设备和Chrome上,我记录了流量,但它从未到达target2.com,也没有任何错误或警告提示。
这仅发生在跨域头部重定向时。是否有其他的头文件可以允许此操作?
1个回答

0

这是一个安全特性。就脚本而言(例如Javascript),该请求被视为危险并被阻止。只允许范围在>= 200 <300的响应。


但是,当被重定向的域设置了正确的CORS头时,这应该是允许的。但是Safari似乎并不关心这一点。 - hrdwdmrbl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接