Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs JWT身份验证使用$http.get,但不使用$http.post_Angularjs_Node.js_Jwt_Mean_Express Jwt - Fatal编程技术网

Angularjs JWT身份验证使用$http.get,但不使用$http.post

Angularjs JWT身份验证使用$http.get,但不使用$http.post,angularjs,node.js,jwt,mean,express-jwt,Angularjs,Node.js,Jwt,Mean,Express Jwt,我是个新手。 我正在使用jwt对api端点进行身份验证'/api/candidates' 在客户端/角度js服务中,我有以下条目 resumeFactory.get = function(candidateName) { return $http.get('/api/candidates', { headers: { Authorization: 'Bearer '+ authenticationService.getToken() }); }

我是个新手。 我正在使用jwt对api端点进行身份验证'/api/candidates'

在客户端/角度js服务中,我有以下条目

resumeFactory.get = function(candidateName) {
   return  $http.get('/api/candidates', {
      headers: {
        Authorization: 'Bearer '+ authenticationService.getToken()     
   });
};
在服务器端,我有:

app.get('/api/candidates', auth, function (req, res) {
if (!req.payload._id) {
    //user not logged in
    console.log(req);
    res.status(401).json({"message": "no  user logged in from candidates"});
}
else {
    Candidate.find({}, function (err, candidates) {
        if (err) {
            res.send(err);
        }
        res.json(candidates);
    });
}
});
这个很好用。i、 e.“auth”能够从标头中提取令牌

当我将所有内容更改为“发布”而不是“获取”时:

app.post()
在客户端上

$http.post()  
在服务器端:

app.post()
我从jwt得到如下错误:

UnauthorizedError: No authorization token was found

对正在发生的事情有什么建议吗?。我可以使用get,但我想知道为什么post不能使用
$http一起使用。post
配置是第二个,而不是第二个,所以请相应地更新参数:

$http.post('/url', { cool: postData }, {
  headers: {
    Authorization: 'Bearer '+ authenticationService.getToken()
  }    
});

更好的方法是,将授权标头添加到所有请求。

如果确实在标头中发布了该令牌,请签入开发工具。@Nonemoticoner我在开发工具中找不到它。不知道如何在请求@Nonemoticoner中查找头文件-我终于能够找到如何检查头文件Networks->xhrtanks Andy Gaskell。