【问题标题】:Invalid character in header content ["authorization"] when sending bearer authorization request from thunder client从迅雷客户端发送承载授权请求时,标题内容[“授权”]中的字符无效
【发布时间】: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

picture 2

谁能帮我提前谢谢

【问题讨论】:

  • 我遇到了几乎相同的问题,尽管我使用“Auth”/“Bearer”选项卡输入值。问题是客户端似乎以某种方式添加了换行符。完全删除所有字符(直到我看到占位符文本),然后重新插入我的令牌没有换行符为我解决了它。

标签: node.js express vscode-extensions


【解决方案1】:

问题在于扩展程序中的拼写错误。

请将 Content-type 替换为 content-type

出现此问题是因为“C”在标题中是大写的。

【讨论】:

  • 还是有同样的问题
  • 它看起来像 Thunder-client 没有将请求转发到 server.js
  • 我个人用的最多的是postman。所以,建议坚持下去:D
【解决方案2】:

我设法通过向下箭头键在“授权”字段中创建了一个新行。

解决方案:删除整个内容,直到enter token palceholder 不可见,然后重新键入。

【讨论】:

    猜你喜欢
    • 2019-12-24
    • 2017-02-22
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多