-1

I am writing a post method in Angular 9 which calls an 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. I have enabled CORS on my AWS API (and deployed it). Also, I have include the following proxy.conf.json in my angular.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. Is there a way to resolve this CORS error?

user100123122
  • 309
  • 4
  • 11
  • 1
    Did you try secure: false ? I think you can find some solution here https://stackoverflow.com/questions/39809008/angular-cli-proxy-to-backend-doesnt-work. – Anglesvar Aug 17 '20 at 19:53

1 Answers1

-1

I'd suggest you follow the Enabling CORS for a REST API resource on AWS docs.

Since the request works from postman that gives us a hint that the issue is most likely client-sided.

Albin
  • 1
  • 1