为了账号安全,请及时绑定邮箱和手机立即绑定

Express js 授权值未定义

Express js 授权值未定义

泛舟湖上清波郎朗 2021-11-18 20:45:33
我打开了两个端口: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 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

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


查看完整回答
反对 回复 2021-11-18
?
拉风的咖菲猫

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

})


查看完整回答
反对 回复 2021-11-18
  • 2 回答
  • 0 关注
  • 113 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信