我想使用oauth身份验证将api与mvc站点连接起来。 为此,我需要通过http请求发送访问令牌,如下所示。
addPostComment: function addPostComment(postid, UserId, comment, accessToken) {
var request = $http({
method: "post",
url: apiPath.addPostComment,
data: {
SocialPostId: postid,
CommentDescription: comment,
CommentedUserId: UserId,
CommentedDate: new Date()
},
params: {
action: "post"
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'bearer ' + accessToken);
}
});
return (request.then(handleSuccess, handleError));
}
参数accessToken有值。但是当我设置为请求标头时,它总是说Authrization:Bearer undefined。
有人能告诉我这段代码有什么问题吗?
答案 0 :(得分:0)
$http({
method: "post",
url: apiPath.addPostComment,
data: {
SocialPostId: postid,
CommentDescription: comment,
CommentedUserId: UserId,
CommentedDate: new Date()
},
params: {
action: "post"
},
headers: {
'Authorization': 'bearer ' + accessToken
}
});
你可以像这样发送HTTP请求......