使用axios请求node.js api问题
你好,我正在尝试访问http://localhost:8080/api/v1/postulant 但我无法在标头中设置访问令牌使用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
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 })
第二次,我收到了:
有人解释为什么第二个有效,第一个无效