Error- Preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

keystrokker picture keystrokker · Sep 20, 2018 · Viewed 19.2k times · Source

I am trying to call a secured rest API from the angular app. This rest API is running on WAS, and it is validating a JWT token. While running the application in google chrome, it is giving the below error:

Response to the preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

The same call is working fine in IE and postman. Could you pls help me here?

Answer

danday74 picture danday74 · Sep 20, 2018

Your server needs to specify the correct CORS headers in its response.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers

Only browsers enforce CORS, thats why it works in POSTMAN, not sure why it is working in IE

See also Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?

If only I had a pound for every time someone asked this question.