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