Error in angularJS using CORS - Response for preflight has invalid HTTP status code 403 on angular post request

0

Dear,

I have this code in angularjs:

$http.post('http://localhost:8080/employee/'
    , $scope.alumno
    ,{headers: {'Content-Type': 'application/json'}}
    ).success(function(data){

        if ( data.err === false ) {
            $scope.actualizado = true;

            setTimeout(function() {
                $scope.actualizado = false;
                $scope.$apply();
            }, 3500);

        };
    });

My API has these data:

//Add employee:
Url: http://localhost:8080/employee
Type request: POST
Add a new employee:
{
 "firstName": "Javier",
 "lastName": "Piedra",
}

Use chrome with an extension that enables CORS for GET works perfect but for POST shows this error:

XMLHttpRequest cannot load http://localhost:8080/employee/. Response for 
preflight has invalid HTTP status code 403

In my app.config I use this:

app.config( function($routeProvider,$httpProvider){

$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};

Do you have a solution for this error?

Greetings

    
asked by juanitourquiza 02.06.2017 в 04:34
source

1 answer

0

After a lot of research I can confirm that doing this action by default can not exist extensions in chrome for example that allows you to use GET but for POST and PUT no longer. The correct thing is to make the change from the API and that way to solve it.

    
answered by 24.06.2017 / 00:16
source