【发布时间】:2021-10-02 06:42:06
【问题描述】:
server.js
我尝试通过thunder-client visual-studio代码扩展发送一个不记名令牌,但出现错误 标题内容中的无效字符[“授权”]
但它与邮递员配合得很好
const express = require('express')
const app = express()
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.get('/',(req,res)=>{
res.status(200).send("welcome to the main page")
})
app.post('/',(req,res)=>{
const bearerHeader = req.headers['authorization']
if(typeof bearerHeader !== 'undefined'){
console.log(req.headers)
console.log(bearerHeader)
res.send(req)
}else{
res.status(403)
}
//bearer.header.split('')
})
app.listen(8000,()=>console.log("server is running"))
package.json
{
"name": "simple express app",
"version": "1.0.0",
"description": "",
"main": "source.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"helmet": "^4.6.0",
"mongoose": "^6.0.7",
"morgan": "^1.10.0",
"nodemon": "^2.0.12"
}
}
the error is shown in this picture
谁能帮我提前谢谢
【问题讨论】:
-
我遇到了几乎相同的问题,尽管我使用“Auth”/“Bearer”选项卡输入值。问题是客户端似乎以某种方式添加了换行符。完全删除所有字符(直到我看到占位符文本),然后重新插入我的令牌没有换行符为我解决了它。
标签: node.js express vscode-extensions