(JavaScript) HTTP Basic Authentication Test
Demonstrates how to do HTTP basic authentication using Chilkat.
// 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"
// }
|