Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
使用axios请求node.js api问题_Node.js_Axios_Request Headers - Fatal编程技术网

使用axios请求node.js api问题

使用axios请求node.js api问题,node.js,axios,request-headers,Node.js,Axios,Request Headers,你好,我正在尝试访问http://localhost:8080/api/v1/postulant 但我无法在标头中设置访问令牌 let headers = { 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjUsImlhdCI6MTYxOTUyNDE4NywiZXhwIjoxNjIwMTI4OTg3fQ.hSXARB-y7rClswYZ380HV5RW77qjYNt5FzW2N

你好,我正在尝试访问http://localhost:8080/api/v1/postulant 但我无法在标头中设置访问令牌

let headers = {
        'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjUsImlhdCI6MTYxOTUyNDE4NywiZXhwIjoxNjIwMTI4OTg3fQ.hSXARB-y7rClswYZ380HV5RW77qjYNt5FzW2NfDd8Vw',
        'Content-Type': 'application/json',
    }
    axios.get("http://localhost:8080/api/v1/postulant", { headers })
在我使用的api上:

app.get('/api/v1/postulant',Auth,function (req,res){
console.log(req.headers)
db.query('SELECT * FROM postulant_view', (err, rows) => {
    if (err) { console.log(err); }
    else {
        console.log(rows)
        let result = rows;
        res.json(result);
    }
})
我请求中的标题给出: [

我尝试过:

app.get('/test',Auth,function (req,res){
console.log(req.headers)
db.query('SELECT * FROM postulant_view', (err, rows) => {
    if (err) { console.log(err); }
    else {
        console.log(rows)
        let result = rows;
        res.json(result);
    }
})
打电话给

let headers = {
        'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjUsImlhdCI6MTYxOTUyNDE4NywiZXhwIjoxNjIwMTI4OTg3fQ.hSXARB-y7rClswYZ380HV5RW77qjYNt5FzW2NfDd8Vw',
        'Content-Type': 'application/json',
    }
    axios.get("http://localhost:8080/test", { headers })
第二次,我收到了:

有人解释为什么第二个有效,第一个无效