将自定义访问令牌作为http请求发送



我想使用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有值。但是当我设置为请求头时,它总是说Autharization:Bearer undefined。

有人能告诉我这个代码出了什么问题吗?

    $http({
      method: "post",
                url: apiPath.addPostComment,
                data: {
                    SocialPostId: postid,
                    CommentDescription: comment,
                    CommentedUserId: UserId,
                    CommentedDate: new Date()
                },
                params: {
                    action: "post"
                }, 
      headers: {
      'Authorization': 'bearer ' + accessToken
      }
    });

你可以发送这样的HTTP请求。。。

最新更新