AngularJS - XMLHttpRequest无法加载URL

时间:2015-12-15 16:56:23

标签: javascript angularjs cors

我是角色新手并试图调用redmine API。

这是我的获得:

XMLHttpRequest cannot load http://url Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

这是控制台:

GET /redmine/issues.json HTTP/1.1
Host: url
Connection: keep-alive
Authorization: Basic c2VyZ2lvLmRlbWF0dGlhOnRlY2htb2JpbGU=
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2592.0 Safari/537.36
Postman-Token: 076cd3f9-ddd2-65d1-724e-3789af7ad559
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: it-IT,it;q=0.8,en;q=0.6,es;q=0.4,en-US;q=0.2
Cookie: _redmine_session=...

同样的GET适用于Postman,这是标题(用fiddler拍摄):

header: 'Access-Control-Allow-Headers: X-Requested-With'

我没有添加任何标题,所以我不知道它是否可以被视为与此GET working with Postman, but not with Ajax?相同的问题。

如果是这种情况,如何清除此标题并使其有效?

我尝试添加此标题

myApp.config(['$httpProvider', function ($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
        ]);

并添加配置对象:

box-sizing

但我仍然遇到同样的错误。

请问我还要添加什么?

0 个答案:

没有答案