Sample code for 30+ languages & platforms
JavaScript

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

var http = new CkHttp();

// 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"
// }