15
如何使CORS XMLHttpRequest直接到IP地址,而不是域。CORS請求到IP而不是域名
例如,我從example1.org加載我的網頁。
我試圖做一個CORS請求http://example2.org/
,這是工作。 對http://192.168.1.100
的CORS請求不起作用。爲什麼?
example.org DNS條目的目標是192.168.1.100。 fiddler2 HTTP嗅探器說,瀏覽器甚至沒有發出請求,檢查從服務器發送的CORS HTTP頭。
我試過Google Chrome 29.0.1510.0 canary版和26.0.1410.64 m版。針對CORS請求
示例代碼(即代碼工作,我不是在example.org原點的頁面上。):
var req = new XMLHttpRequest();
req.withCredentials = false;
req.open('GET', 'http://example2.org:8088/GetMyData', true);
req.onreadystatechange = function() {
console.log(req.responseText);
};
req.send();