I am trying to put an authorization header in my requests but it doesn\'t work.
I am using this:
var config = {headers: {
\'Authorization\': token
Try this:
$http({
url : "127.0.0.1/login",
method : 'GET',
headers : {
Content-Type : 'application/json',
Authorization: token
}
}).success(function(data){
alert("login Successfully");
}).error(function(error){
alert("login error");
})
Authorization can't be plain.
specify weather its a Basic
or Bearer
Authorization
Something like
$http.defaults.headers.common['Authorization'] = 'Basic ' + token;
or
$http.defaults.headers.common['Authorization'] = 'Bearer ' + token;
I was having this same issue and it turned out the issue had to do with Apache configuration on the server side. One thing I did find that might be useful to you here is that my Authorization token is sent in the preflight request headers rather than the main request, so it might not appear to be in the headers of the request when you look at it in the developer tools.
I'm setting my defaults like this:
app.config(function($httpProvider) {
$httpProvider.defaults.common['Authorization'] = token;
// For angular 1.5, use:
// $httpProvider.defaults.headers.common['Authorization'] = token;
});