简体   繁体   English

AngularJS HTTP POST无访问控制-允许起源CORS

[英]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.

相关问题 由于没有 Access-Control-Allow-Origin 标头但标头存在而被 CORS 阻止的 HTTP 请求 - HTTP request blocked by CORS for not having Access-Control-Allow-Origin header but the header is present Django CORS Access-Control-Allow-Origin缺失 - Django CORS Access-Control-Allow-Origin missing Flask CORS - 重定向上没有Access-control-allow-origin标头() - Flask CORS - no Access-control-allow-origin header present on a redirect() 被 CORS 策略阻止:No"Access-Control-Allow-Origin" Using Flask - Blocked by CORS policy: No"Access-Control-Allow-Origin" Using Flask Django CORS 问题:不允许访问控制允许来源 - Django CORS issue: access-control-allow-origin is not allowed 我在React中编写axios post方法并添加Access-Control-Allow-Origin,但请求无法正常工作,并且响应我cors原点错误 - I write axios post method in React and add Access-Control-Allow-Origin but request is not working and response to me cors origin error AngularJS中不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header present AngularJS AWS 对 XMLHttpRequest 的访问已被 CORS 策略阻止:No 'Access-Control-Allow-Origin' header - AWS Access to XMLHttpRequest at from origin has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header Flask / Flask-CORS:缺少CORS标头“ Access-Control-Allow-Origin” - Flask/Flask-CORS: CORS header ‘Access-Control-Allow-Origin’ missing Webfaction已被CORS策略阻止从来源“ http:// mydomain”访问domain / fonts / fontname.ext的字体:No'Access-Control-Allow-Origin' - Webfaction Access to font at domain/fonts/fontname.ext from origin 'http://mydomain' has been blocked by CORS policy: No 'Access-Control-Allow-Origin'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM