Sample code for 30+ languages & platforms
Node.js

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    var http = new chilkat.Http();

    //  To use HTTP Basic authentication:
    http.Login = "myLogin";
    http.Password = "myPassword";
    http.BasicAuth = true;

    //  Run the test using this URL with the credentials above.  
    //  (Works while httpbin.org keeps the test endpoint available.)
    var jsonResponse = http.QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword");
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log("Response status code: " + http.LastStatus);

    console.log(jsonResponse);

    //  Output:

    //  Response status code: 200
    //  {
    //    "authenticated": true, 
    //    "user": "myLogin"
    //  }

}

chilkatExample();