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?

javapenguin
  • 966
  • 2
  • 22
  • 38
  • where have you added the config values ? – Alok Mar 02 '16 at 09:13
  • Possible duplicate of [angularJS sending OPTIONS instead of POST](https://stackoverflow.com/questions/30704283/angularjs-sending-options-instead-of-post) – juliocesar Apr 11 '18 at 21:50

1 Answers1

1

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

AbiSivam
  • 419
  • 1
  • 6
  • 17