首页 > 解决方案 > 在 NodeJS 中设置不记名令牌

问题描述

我有一个使用 NodeJS 的 Web 后端。我想使用链接从另一台服务器检索数据,例如https://evoDMSTDev/api/api_event_all.php,并且必须使用不记名令牌71D55F6907509来访问它。那么,我必须在哪里设置令牌,以便我可以检索该数据并将其显示在我的 Web 后端?

感谢您的帮助 :)

标签: node.jsbearer-token

解决方案


我在节点 js 中创建这样的,然后只需调用obj你的.ejs

request({
    uri : 'https://evoDMSTDev/api/api_events_all.php',
    auth: {
        'bearer': '71D55F99570209'
    },
    rejectUnauthorized: false,//add when working with https sites
    requestCert: false,//add when working with https sites
    agent: false,//add when working with https sites
}, function(error, response, body) {
      if (error) {
         console.log(error);
      } else {
         obj = JSON.parse(body);
      }
}

推荐阅读