$ http.post发送授权标头 [英] $http.post send Authorization Header
本文介绍了$ http.post发送授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将带有$ http.post调用的授权标头传递给.NET Web API服务.
I am attempting to pass an Authorization Header with a $http.post call to a .NET Web API service.
如果我使用这个:
$http.post(urls.getEmployeeInfo,
{
withCredentials: true,
headers:{ 'Authorization': 'Basic ' + btoa(username + ":" + password)}
}
);
授权"标头未发送到我的服务.
The Authorization header does not get sent to my service.
以下作品:
$http({
url: urls.getEmployeeInfo,
method: "POST",
withCredentials: true,
headers: {
'Authorization': 'Basic ' + btoa(username + ":" + password)
}
});
为什么$ http.post不发送授权标头?
Why doesn't $http.post send the Authorization Header ?
谢谢
推荐答案
$http
takes only one argument: config
[documentation]
$http.post
接受三个参数:url
,data
和(和可选)config
[
$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)}
}
);
这篇关于$ http.post发送授权标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文