2013-04-03 87 views
3

試圖通過302從一臺服務器重定向到另一臺沒有內容的服務器,僅用於跟蹤目的,我擔心會丟失一些使用Apple iOS設備的訪問者, Webkit/Chrome瀏覽器。AJAX:301/302頭部重定向(跨域)在某些Webkit瀏覽器中失敗

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的/鍍鉻/移動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到達,停止沒有錯誤或警告。

這只是發生跨域重定向頭,是否有額外的頭允許這樣做?

回答

0

這是一個安全功能。據作爲腳本(例如, Javascript)請求被認爲是危險的並且被阻止。只允許在> = 200 < 300範圍內的回覆。

+0

但是,當正在被重定向到的域設置正確的CORS頭時,應該允許這樣做。但Safari似乎並不在乎這一點。 – hrdwdmrbl

相關問題