Express js 授权值未定义

我打开了两个端口:3000 和 4000。我想从 3000 传递授权标头并在端口 4000 上接收它。


我正在从 3000 端口传递授权值


app.get('/',function(req,res){

  console.log('redirect');

  res.header('Authorization', 'my sample');

  res.redirect('http://localhost:4000/api/oauth2');

});

在 4000 端口上接收


app.get('/api/oauth2', (req, res)=> {

  console.log(req.headers.authorization); // undefined

  res.end('i reached');

})

我如何从 3000 到 4000 端口接收这个值?


泛舟湖上清波郎朗
浏览 114回答 2
2回答

守候你守候我

您可以使用在客户端发出请求的 .html 文件返回“/”请求,也可以在 url 查询中设置身份验证令牌。

拉风的咖菲猫

您必须使用来自 npm 的请求包,它是一个 http 客户端。npm install request导入请求模块。const request = require('request');let options = {   url: "http://localhost:4000/api/oauth",  headers:{        authorization: "your_authorization_token"   }request.get(options, (err, response, body)=>{// Handle response})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript