使用带有https的身份验证在nodejs中使用get API

问题描述 投票:0回答:1

如何发送Id and password表示basic authentication到以下代码。我的意思是我需要在下面的代码中输入id / pass?我的API需要基本身份验证

const https = require('https');

https.get('https://rws322s213.infosys.com/AIAMFG/rest/v1/describe', (resp) => {
  let data = '';
  resp.on('data', (chunk) => {
    data += chunk;
  });


  resp.on('end', () => {
    console.log(JSON.parse(data).explanation);
  });

}).on("error", (err) => {
  console.log("Error: " + err.message);
});
node.js rest node-modules
1个回答
0
投票

为了请求Basic authentication,客户端将http Authorization header传递给服务器。该标头采用以下形式:

    Authorization: Basic Base64EncodedCredentials

因此,您的问题是“如何通过https.get()请求传递标头?”

It goes in options.headers{},您可以像这样放置它:

options.headers{}
© www.soinside.com 2019 - 2024. All rights reserved.