AngularJS $http GET method to backend server: Request Method:OPTIONS 405

167 views Asked by At

$http GET request to a clojure backend, to get a list of services. I get is an OPTIONS request (???), which gets a 405 response...

<code>
var config = {headers:  {
        'Authorization': 'Bearer d2VudHdvYW5nZV9tZQ',
        "X-Testing" : "testing"
    }
};
$http.get(SERVER.MESSAGE_SERVICES, config)
  .success(function(successCallback) {
    $scope.services = successCallback;
  })
  .error(function(errorCallback) {
    console.log(errorCallback.toString);
  }).
finally(function() {
  console.log("Message services rest call");
});
</code>

**clojure  backend**:
<code>
headers {"Access-Control-Allow-Origin" "*"
         "Access-Control-Allow-Headers" "X-Requested-With, Origin,Content-Type, Accept"
         "Access-Control-Allow-Methods" "GET, POST, OPTIONS"}
</code>
2

There are 2 answers

1
raso On BEST ANSWER

There is no problem that AngularJS sends an OPTIONS request, that is because CORS standards force to do so. Be sure that the server is configured to allow a GET method.

0
Gopal Yadav On

Yes as raso suggested this problem is because of Cross Origin Resource Sharing(CORS). The same old privacy policy prevents JS/ angularJS from making requests across domain boundaries.

Configure server to allow cross domain requests. Or If you are using Chrome than you can use this extension to surpass this problem.