DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Using Truffle L2 Boxes to Bridge Blockchain Networks
  • Nginx + Node.JS: Perform Identification and Authentication
  • Gossip on Cryptography: Part 3
  • Node.js Microservices Architecture: A Complete Guide

Trending

  • Your Terraform Monolith Isn't Too Big. It's Tightly Coupled.
  • Beyond Clicking Buttons: Build a Browser Agent That Verifies Its Results With Playwright MCP
  • Building an AI System That Makes Your Entire Company Queryable: A Startup's Guide
  • How to Build a Production-Ready iOS App With AI-Generated Code
  1. DZone
  2. Coding
  3. JavaScript
  4. Node.js Call HTTPS With BASIC Authentication

Node.js Call HTTPS With BASIC Authentication

By 
Santiago Urrizola user avatar
Santiago Urrizola
·
Jul. 29, 13 · Code Snippet
Likes (2)
Comment
Save
Tweet
Share
106.9K Views

Join the DZone community and get the full member experience.

Join For Free

Node.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
  • Gossip on Cryptography: Part 3
  • Node.js Microservices Architecture: A Complete Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook