Reputation: 7241
I am attempting to pass an Authorization Header with a $http.post call to a .NET Web API service.
If I use this :
$http.post(urls.getEmployeeInfo,
{
withCredentials: true,
headers:{ 'Authorization': 'Basic ' + btoa(username + ":" + password)}
}
);
The Authorization header does not get sent to my service.
The following works :
$http({
url: urls.getEmployeeInfo,
method: "POST",
withCredentials: true,
headers: {
'Authorization': 'Basic ' + btoa(username + ":" + password)
}
});
Why doesn't $http.post send the Authorization Header ?
Thanks
Upvotes: 1
Views: 9676
Reputation: 4481
$http
takes only one argument: config
[documentation]
$http.post
takes three arguments: url
, data
, (and an optional) config
[documentation]
So if you want to pass configuration options, such as headers, you need to send them as the third argument, rather than the second:
$http.post(urls.getEmployeeInfo, postData,
{
withCredentials: true,
headers:{ 'Authorization': 'Basic ' + btoa(username + ":" + password)}
}
);
Upvotes: 6