[英]AngularJS HTTP POST No Access-Control-Allow-Origin CORS
I'm building an app using Cordova and AngularJS. 我正在使用Cordova和AngularJS构建应用程序。 I have backend api running on heroku.
我在heroku上运行了后端api。 I want to make a POST request to the api and send JSON data to it.
我想向api发出POST请求并向其发送JSON数据。 I have set the following headers on my server:
我在服务器上设置了以下标头:
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Access-Control-Allow-origin
Access-Control-Allow-Headers: Origin, X-Requested-With, Consent-Type, Accept Via 1.1 vegur
When I run this request, I get the following error: 运行此请求时,出现以下错误:
XMLHttpRequest cannot load https://someservername.com/api/v1.0/someroute. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mywell.app' is therefore not allowed access.
However, when I make the request using curl, It works fine. 但是,当我使用curl发出请求时,它可以正常工作。
My Angular code does the following: 我的Angular代码执行以下操作:
$http({
url : "https://someservername.com/api/v1.0/someroute",
method : 'POST',
headers : {"content-type" : "application/json"},
data : {"user":"ab123", "isSet":true}
}).success(function(data, status, headers, config){
console.log(data);
}).error(function(data, status, headers, config){
console.log(status);
});
Did you find a solution? 您找到解决方案了吗? If not...
如果不...
Add www 新增www
Change this https://someservername.com/api/v1.0/someroute 更改此https://someservername.com/api/v1.0/someroute
To this https://www.someservername.com/api/v1.0/someroute 到此https://www.someservername.com/api/v1.0/someroute
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.