如何发送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);
});
为了请求Basic authentication,客户端将http Authorization header传递给服务器。该标头采用以下形式:
Authorization: Basic Base64EncodedCredentials
因此,您的问题是“如何通过https.get()
请求传递标头?”
It goes in options.headers{}
,您可以像这样放置它:
options.headers{}