我想在 Angular js 中的 $http.post 请求的 header 上设置授权。
在简单的 html ajax 上它可以工作:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) { //do something
}
};
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Authorization", "xxxxxxxxxx");
xhttp.send();
在 Angular 上我收到一条错误消息 - “无法读取未定义的属性‘协议(protocol)’”
var configHeader = {
headers: {
'Authorization': 'xxxxxx'
}
};
$http.post(url, configHeader).then(function(response) {
//do something
});
请帮忙。
最佳答案
$http.post
有 3 个参数:
- 网址
- 数据
- 配置(可选)
您缺少要发布的数据...
关于javascript - 将 header 授权设置为 Angular $http post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35310194/