![](/img/trans.png)
[英]HTTP request blocked by CORS for not having Access-Control-Allow-Origin header but the header is present
[英]AngularJS HTTP POST No Access-Control-Allow-Origin 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發出請求時,它可以正常工作。
我的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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.