I am trying to replicate this curl using angular $http.get,
curl -H "Accept: application/json" http://localhost:3000/posts -H 'Authorization: Token token="1111"'
but I am not sure how to properly set the angular header
this is how I tried it,
app.controller('newsCtrl', function($http, $scope){
$scope.news =[];
$http.get('http://localhost:3000/posts.json', {
headers: {"Authorization": "Token[token]=1111"}).success(function(response){
console.log(response)
})
})
So how do I properly set the header?
Thank you ps: I am not using Basic authentication.
To send a GET request with a Bearer Token authorization header, you need to make an HTTP GET request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header.
The token is a text string, included in the request header. In the request Authorization tab, select Bearer Token from the Type dropdown list. In the Token field, enter your API key value. For added security, store it in a variable and reference the variable by name.
If you want the Authorization header to contain Token token="1111"
, then this should work. It looks like your brackets were not matching up also.
$http.get('http://localhost:3000/posts.json', {
headers: {
"Authorization": 'Token token="1111"'
}
}).success(function(response){
console.log(response)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With