angularjs – Response for preflight has invalid HTTP status code 403 on angular post request
If you utilizing java restful controller as your server.nYou can seek advice from https://spring.io/guides/gs/rest-service-cors/
n
I added @CrossOrigin(origins = *) on my controller and it really works.nBasically, you can’t do something within the shopper facet.
n
Lin
‘
Ok so heres how I figured this out. It all has to do with CORS coverage. Before the POST request, Chrome was doing a preflight OPTIONS request, which ought to be dealt with and acknowledged by the server previous to the precise request. Now that is actually not what I wished for such a easy server. Hence, resetting the headers shopper facet prevents the preflight:
n
app.config(operate ($httpProvider) {n $httpProvider.defaults.headers.frequent = {};n $httpProvider.defaults.headers.post = {};n $httpProvider.defaults.headers.put = {};n $httpProvider.defaults.headers.patch = {};n});n
n
The browser will now ship a POST instantly. Hope this helps a whole lot of of us on the market… My actual drawback was not understanding CORS sufficient.
n
Link to an amazing clarification: http://www.html5rocks.com/en/tutorials/cors/
n
Kudos to this reply for exhibiting me the way in which.nAngularJS POST Fails: Response for preflight has invalid HTTP status code 404
‘
angularjs – Response for preflight has invalid HTTP status code 403 on angular post request
I’ve this code in angularjs:
n
$http.post(http://localhost:8080/worker/n , $scope.alumnon ,{headers: {Content-Type: utility/json}}n ).success(operate(knowledge){nn if ( knowledge.err === false ) {n $scope.actualizado = true;nn setTimeout(operate() {n $scope.actualizado = false;n $scope.$apply();n }, 3500);nn };n });n
n
My API have this knowledge:
n
//Add worker:nUrl: http://localhost:8080/employeenType request: POSTnAdd a brand new worker:n{n firstName: Javier,n lastName: Piedra,n}`n
n
I exploit chrone with extension for out there CORS for the GET all good however post pattern this error:
n
XMLHttpRequest can't load http://localhost:8080/worker/. Response for npreflight has invalid HTTP status code 403n
n
In my app.config use:
n
app.config( operate($routeProvider,$httpProvider){nn$httpProvider.defaults.headers.frequent = {};n$httpProvider.defaults.headers.post = {};n$httpProvider.defaults.headers.put = {};n$httpProvider.defaults.headers.patch = {};n
n
Maybe this generally is a answer for your problem.
n
Regards
Related posts on angularjs :