user3012606
user3012606

Reputation: 11

How to send authorization header to a http request in angular js (version 1.4.8)

snapshot on server side

The above screenshot is while I debug the web service which is hit during my javascript call. I want to set the authorization header of the http request which is returning null. Can you please suggest me for this

Upvotes: 0

Views: 4943

Answers (2)

Manwal
Manwal

Reputation: 23816

You can add this in your http request:

headers: {'Authorization': 'Basic key'}

Examples

GET request:

$http.get('url', { //same for post also
    headers: {'Authorization': 'Basic key'}
});

Post Request:

$http.post("url", requestData, {
    headers: { 'Authorization': 'Basic yourkey'}
}).success(function(responseData) {
    //do stuff with response
});

Upvotes: 0

jsNovice
jsNovice

Reputation: 646

 var config = {
      method: 'POST',
      url: 'https://somesite.com/',
      headers: {
            // key value pair of headers
            'Authorization': 'Your auth key'
      },
      data: body of request
  };
 $http(config)
         .success(function(){})
         .error(function(){})

Upvotes: 2

Related Questions