我尝试从我的角度登录服务POST:
$http.post('https://xyz/login', { headers: { 'Content-type': 'application/json', 'Accept': 'application/json', 'signature': 'asd' }
我收到这个错误:
XMLHttpRequest cannot load https://xyz/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1337' is therefore not allowed access.
我试过这个标题:
$httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With'];
还有这些:
"Access-Control-Allow-Origin": "*"; "Access-Control-Allow-Headers": "X-Requested-With"; "Access-Control-Allow-Methods": "GET, POST", "PUT", "DELETE";
有趣的是,POSTMAN是有效的.我该怎么办?
谢谢.
您的请求包含非简单标头Content-type
,signature
并且必须包含在响应的Access-Control-Allow-Headers
标头中.
(Content-type
有时是一个简单的标题,但只针对特定的值.application/json
不是这些值中的一个,它会导致Content-type
变得非常简单.)
添加Content-type
到Access-Control-Allow-Headers
服务器的预检响应中.
POSTMAN不受同源策略的约束,因此它不需要来自服务器的CORS支持.