好吧,我已经查遍了这个。基本上我们使用的是跨域请求的 $http 请求。我们的服务器允许该域,当请求返回 200 时,一切正常。然而,每当我们的服务器返回错误,500、401,无论什么时候,Angular 都会认为这是 CORS 问题。
我使用 Fiddler 调试了响应,以验证我的服务器是否返回了 500,但 Angular 却卡住了。
这是请求:
var params = {
url: "fakehost/example",
method: 'GET',
headers: {
"Authorization": "Basic encodedAuthExample"
}
};
$http(params).then(
function (response) { // success
},
function (error) { // error
// error.status is always 0, never includes data error msg
});
然后在控制台中,我会看到:
XMLHttpRequest 无法加载 fakehost/example。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源“mylocalhost:5750”。
然而,在 fiddler 中,真正的响应是:
HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 26 Aug 2014 12:18:17 GMT
Content-Length: 5683
{"errorId":null,"errorMessage":"Index was outside the bounds of the array.","errorDescription":"Stack trace here"}
我使用的是 AngularJS v1.2.16
我想我找到了答案,看起来你必须在你的 asp.net 管道中注入正确的 CORS 标头,如上所述here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)