我打开了两个端口: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 端口接收这个值?
2 回答
![?](http://img1.sycdn.imooc.com/545863b500014e4602200220-100-100.jpg)
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
您必须使用来自 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
})
添加回答
举报
0/150
提交
取消