Trending
- RAG Done Right: When to Use SQL, Search, and Vector Retrieval and How To Combine Them
- Mastering Fluent Bit: Beginners' Guide for Contributing to our CNCF Project Docs
- 8 Major Challenges Faced by Android Application Developers
- Reproducible Development Environments, One Command Away: Introducing CodingBooth
- DZone
- Coding
- JavaScript
- Node.js Call HTTPS With BASIC Authentication
Node.js Call HTTPS With BASIC Authentication
Join the DZone community and get the full member experience.
Join For FreeNode.js https module used to make a remote call to a remote server using https and BASIC authentication:
var options = {
host: 'test.example.com',
port: 443,
path: '/api/service/'+servicename,
// authentication headers
headers: {
'Authorization': 'Basic ' + new Buffer(username + ':' + passw).toString('base64')
}
};
//this is the call
request = https.get(options, function(res){
var body = "";
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
//here we have the full response, html or json object
console.log(body);
})
res.on('error', function(e) {
onsole.log("Got error: " + e.message);
});
});
}
HTTPS
Node.js
authentication
Opinions expressed by DZone contributors are their own.
Related
-
Using Truffle L2 Boxes to Bridge Blockchain Networks
-
Nginx + Node.JS: Perform Identification and Authentication
-
The Trust Problem in Modern SaaS: Why Your Authentication Succeeded, and You Still Got Breached
-
Your API Authentication Isn’t Broken; It’s Quietly Failing in These 6 Ways
Partner Resources
×
