NodeJS Thunder客户端发送承载授权请求时头内容[“authorization”]中字符无效

bd1hkmkf  于 2023-05-22  发布在  Node.js
关注(0)|答案(3)|浏览(189)

server.js

我尝试通过thunder-client visual-studio代码扩展发送承载令牌,但收到错误头内容[“authorization”]中的字符无效

  • 但和 Postman 一起工作很好 *
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"))

包.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
有人能帮我在此提前感谢

d5vmydt9

d5vmydt91#

问题在于扩展中的排印错误。
请将内容类型替换为内容类型
出现此问题是因为标题中的“C”是大写的。

yduiuuwa

yduiuuwa2#

我设法通过向下按箭头键在“授权”字段中创建了一个新行。
解决方案:删除整个内容,直到enter token palceholder不可见,然后阿金输入。

nhaq1z21

nhaq1z213#

我在另一个工具的一个完全不相关的(大部分)Github线程上看到了它。如果您从浏览器复制令牌,而不是Ctrl+CCtrl+V-ing它,只需右键单击并选择Copy value,它应该工作。这是因为在你复制的文本中有一个省略号(三个点),很可能。
这是一个很好的例子。https://github.com/Huachao/vscode-restclient/issues/942#issuecomment-1054272212
这就是你需要做的(它是西班牙语的,但它在第一行写着Copy value,在第二行写着Copy all):

相关问题