收到此错误消息:
Refused to set unsafe header "Origin"
使用此代码:
function getResponse() {
document.getElementById("_receivedMsgLabel").innerHTML += "getResponse() called.<br/>";
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
receiveReq.open("GET", "http://L45723:1802", true, "server", "server123"); //must use L45723:1802 at work.
receiveReq.onreadystatechange = handleReceiveMessage;
receiveReq.setRequestHeader("Origin", "http://localhost/");
receiveReq.setRequestHeader("Access-Control-Request-Origin", "http://localhost");
receiveReq.timeout = 0;
var currentDate = new Date();
var sendMessage = JSON.stringify({
SendTimestamp: currentDate,
Message: "Message 1",
Browser: navigator.appName
});
receiveReq.send(sendMessage);
}
}
我究竟做错了什么?为了使这个 CORS 请求正常工作,我在标题中缺少什么?
我尝试删除receiveReq.setRequestHeader("Origin", ...)
呼叫,但 Google Chrome 在我的receiveReq.open()
呼叫中引发访问错误...
为什么?