我得到一个405错误使得从本地主机的请求,这是完全错误:405方法
OPTIONS http://www.myurl.com 405 (Method Not Allowed)
XMLHttpRequest cannot load http://www.myurl.com . Response for preflight has invalid HTTP status code 405
我理解的问题,但怪癖是,我得到这个错误只是当我使用的角度$ http服务:
var req = {
method: 'POST',
url: 'http://www.myurl.com',
headers: {
'Content-Type': 'application/json'
},
data: {
}
}
$http(req)
.then(function(res) {},
function(error) {});
使用XMLHttpRequest的完美的作品:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(xhttp.responseText);
}
};
xhttp.open("POST", 'http://www.myurl.com', true);
xhttp.send();
我有一个chrome扩展来添加CORS头文件并且它正在工作。我还注意到,如果我删除了xhttp.open中的第三个参数,那么错误再次出现。
¿有谁知道原因? ¿如何在不出错的情况下使用角度服务?