AngularJS HTTP POST No Access-Control-Allow-Origin CORS

时间:2015-07-24 14:58:39

标签: python angularjs cross-domain cors flask-cors

我正在使用Cordova和AngularJS构建应用。我在heroku上运行后端api。我想向api发出POST请求并向其发送JSON数据。我在服务器上设置了以下标题:

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

当我运行此请求时,出现以下错误:

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.

但是,当我使用curl发出请求时,它工作正常。

My 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);
    });

1 个答案:

答案 0 :(得分:-1)

您找到了解决方案吗? 如果不是......

添加www

改变这个 https://someservername.com/api/v1.0/someroute

对此 https://www.someservername.com/api/v1.0/someroute