简体   繁体   English

从 Angular 9 调用 AWS api 给出 cors 错误

[英]Call to AWS api from Angular 9 giving cors error

I am writing a post method in Angular 9 which calls an AWS API.我正在 Angular 9 中编写一个 post 方法,它调用 AWS API。 However, when I call the post function in Angular 9: this.http.post(url, body, requestOptions) , in my browser I get the following error: Access to XMLHttpRequest at 'url' as been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response. However, when I call the post function in Angular 9: this.http.post(url, body, requestOptions) , in my browser I get the following error: Access to XMLHttpRequest at 'url' as been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response. I have enabled CORS on my AWS API (and deployed it).我在我的 AWS API 上启用了 CORS(并部署了它)。 Also, I have include the following proxy.conf.json in my angular.json : {另外,我在我的angular.json proxy.conf.json {

 "/api/*": { "target": "url", "secure": true, "changeOrigin": true }

} but I am still getting the cors error.但我仍然收到}错误。 I have tested my POST request using Postman, and the request runs perfectly.我已经使用 Postman 测试了我的 POST 请求,并且请求运行完美。 Is there a way to resolve this CORS error?有没有办法解决这个 CORS 错误?

I'd suggest you follow the Enabling CORS for a REST API resource on AWS docs.我建议您遵循 AWS 文档上的为 REST API 资源启用 CORS

Since the request works from postman that gives us a hint that the issue is most likely client-sided.由于该请求来自 postman,因此我们暗示该问题很可能是客户端问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Angular 中进行服务器端 API 调用以绕过 CORS 错误 - How to do a server side API call in Angular to bypass CORS error 尝试在 angular 前端调用 MS 图形 api 时出现 CORS 错误 - CORS error when trying to call MS graph api in angular frontend Spring MVC API 调用仅在从 ZC31C335EF37283C451B18BA0DD317DE 调用时获取 CORS 错误。 从 Java 调用 API 工作正常 - Spring MVC API call gets CORS error only when calling from Angular. Calling the API from Java works fine though AWS Api Gateway 403错误-从所有来源启用CORS - AWS Api Gateway 403 error - CORS enabled from all origins Angular 7 CORS同时给出错误和数据 - Angular 7 CORS giving error and data at same time 角度4中AWS API Gateway的CORS问题 - CORS issue with AWS API Gateway in angular 4 身份服务器 CORS 从 Angular 客户端调用 API 时出错 - Identity server CORS error while calling API from Angular client 从API重定向到Identityserver时出现Angular2 CORS错误 - Angular2 CORS error when being redirected from API to Identityserver gem“rack-cors”不工作并且从angular客户端请求到rails api抛出cors错误 - gem "rack-cors" not working and request from angular client to rails api throwing cors error 尝试调用本地托管节点 express api 时,在我的 angular 应用程序中出现 CORS 错误 - Getting CORS error in my angular application when try to call local hosted node express api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM