gpt4 book ai didi

javascript - 将 header 授权设置为 Angular $http post

转载 作者:行者123 更新时间:2023-11-28 06:23:43 25 4
gpt4 key购买 nike

我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com