I try to execute CORS request in Angular (4.2.4) and everything works fine when using GET method. But when executing POST request I get this error:
Response for preflight has invalid HTTP status code 403
There's headers screenshot:
-
Its not a backend problem. I think it is an API Service problem– DhyeyOct 30, 2017 at 12:39
-
Add options request's wildcard url to resolve cors with allow headers which you willbe sending manually, allow methods get post put delete & allow origin to your host or * . E.g. option method for /api/web/v2/*– PriyaOct 30, 2017 at 16:37
1 Answer
It is expected behaviour. Since your request is not a simple request, the browser did a preflight request as OPTIONS method.
Your API server doesn't support this method.
Solution to this is add support to OPTIONS method in your API. When there's OPTIONS method and 'origin' header in the request header, response a blank content with "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Headers" headers.
As implementation in PHP, found an answer here: Backbone & Slim PHP - Access-Control-Allow-Headers - Can GET information, can't POST it?
Once the client browser receives the OPTIONS response, with applicable access-control-allow-* headers, it will raise the POST request following.