gpt4 book ai didi

angularjs - 如何在Header Angular JS中传递授权 token

转载 作者:行者123 更新时间:2023-12-03 14:44:34 24 4
gpt4 key购买 nike

在我的 Controller 中,我试图调用我的 API,但我无法传递授权 token 。

我创建了一个配置变量并在其中传递了我的 token ,但得到了以下响应:

900902Missing CredentialsRequired OAuth 凭据未提供。确保您的 API 调用具有标题:“授权:不记名 ACCESS_TOKEN”

** JS 代码 **

 app.controller("AuthenticationController", function($scope, API_URL, vcRecaptchaService, $http) {

var config = {
headers: {
'Authorization': 'Bearer 00000-e5673-346756f-8676-f7567561a'
}
};
$scope.verifyRecaptcha = function() {

if (vcRecaptchaService.getResponse() === "") {
alert("User did not resolve the recaptcha")
} else {
var post_data = {
'g-recaptcha-response': vcRecaptchaService.getResponse()
}
$http.post('https:1.1.1.1/abc/vdc/verify', config, post_data).success(function(response) {

if (response.success === true) {
alert("Successfully resolved the recaptcha.");
} else {
alert("User verification failed");
}
})
.error(function(error) {
alert("Error Occured while resolving recaptcha.");
console.log(error);
})
}
}

最佳答案

我想你已经切换了有效载荷和标题的位置

应该http.post(url, data, config)而不是 http.post(url, config, data)
链接到 doc

我建议将所有逻辑放在 http 拦截器中,因此 auth header 将附加到每个请求。

关于angularjs - 如何在Header Angular JS中传递授权 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45028150/

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