0

I am trying to do a $http.post, but this response give me this error.

XMLHttpRequest cannot load http://XXXXXXXXX:2222/server/api/v1/controllers. Response for preflight has invalid HTTP status code 403

All of I read on internet sais that Its a fault by the CORS, I try to solve this with no success.

Here is my $http.post method.

        // Set the Content-Type 
        $http.defaults.headers.post["Content-Type"] = "application/json";

        // Delete the Requested With Header
        delete $http.defaults.headers.common['X-Requested-With'];



        var config = {
            method: 'POST',
            headers: {'Content-Type': 'application/json; charset=utf-8'}
         }

        $http.post("http://XXXXXXXXX:2222/server/api/v1/controllers", objToSave , config)
          .then(function successCallback(response) {
            // this callback will be called asynchronously
            // when the response is available
            console.log(response)
          }, function errorCallback(error) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
            console.log(error)
          });

I am using Angular v1.5.5.

I hope You can help me,

Regards!

2
  • CORS error => Check the CORS configuration on your server side Commented Feb 14, 2017 at 12:08
  • Does this help: stackoverflow.com/a/38333662/1225328? Commented Feb 14, 2017 at 12:10

1 Answer 1

2

chrome first send preflight request to check if server responds properly. If server properly handles that preflight request, then original request will be sent by chrome. Try to add below line in your server request handler header.

Access-Control-Allow-Origin: *
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.