$http POST call in angularjs returns HTTP status code 405 $http POST call in angularjs returns HTTP status code 405 angularjs angularjs

$http POST call in angularjs returns HTTP status code 405


Request Method:OPTIONS

The client is making a pre-flight OPTIONS request to the server.

An OPTIONS request is automatically made by the browser before making a non-simple (e.g. not a GET) cross domain (CORS) request.

The purpose of the OPTIONS request is a quick check with the server to ensure that the client is permitted to make the POST before actually making the POST. Thus the client makes 1 or 2 requests.

An OPTIONS request and if the OPTIONS request responds with success (not a 405) then make the POST.

The OPTIONS request is failing most likely because you have not stated in your server response that your server supports OPTIONS requests.

Add this header to your server response ..

Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS

Then it should all work.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests for more info