To use http.client in Node.js if there is basic authorization, we call request
with the token in the header.
For instance, we write
const username = "Test";
const password = "123";
const auth =
"Basic " + Buffer.from(username + ":" + password).toString("base64");
const header = { Host: "www.example.com", Authorization: auth };
const request = client.request("GET", "/", header);
to create the basic auth
token.
Then we call client.request
with the header
object which has the Authorization
header set to the basic auth
token.