PHP
Chilkat2 PHP
HTTP Basic Authentication Test
Demonstrates how to do HTTP basic authentication using Chilkat.Chilkat PHP Downloads
<?php
use Chilkat2\Http;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new 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.)
try {
$jsonResponse = $http->QuickGetStr('https://httpbin.org/basic-auth/myLogin/myPassword');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo 'Response status code: ', $http->LastStatus, "\n";
echo $jsonResponse, "\n";
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }