1

I am trying to send authorization info in a header using Angular $http.get.

If I call $http.get without config, it send the request only once.

As soon as I add a config with header info, it sends the request twice to the server. Once without the authorization header and the second time with.

Here is my code:

var config = {
    headers: {
        Authorization: authorization
    },
    withCredentials: true
};

$http.get(url, config).success(function (response) {
    $scope.records = validateResponse(response);
});

How can I get it to send only one request with the header information?

2

1 Answer 1

1

Try modifying the default http header of angularjs and make the request. $http.defaults.headers.common.Authorization = 'token';

Sign up to request clarification or add additional context in comments.

2 Comments

$http.defaults.headers.common.Authorization also send the request twice
The first request sent through is method OPTIONS and the second is GET

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.