Response to Preflight Request Doesn't Pass Access Control Check (Angular2)

Angular 2 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header

That's a CORS issue. It happens because you are trying to request a resource from a different host. Your API needs to answer those OPTIONS requests properly otherwise the browser is going to block the request.

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

CORS protection isn't implemented in postman so your request works fine there.

Edit: You can also use webpack / angular cli's proxy support if your backend is going to run on the same host in production:
https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

Response to preflight request doesn't pass access control check: It does not have HTTP ok status in angular

CORS should be server-side issue, not Angular.

Anw just for development purposes you can open Chrome with the option --disable-web-security. You can check the ref here: Disable same origin policy in Chrome

Angular2-Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

CORS headers like

headers.append('Access-Control-Allow-Origin','*');

need to be provided by the server. Adding them on the client is pointless.



Related Topics



Leave a reply



Submit