(PHP ActiveX) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
<?php
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new COM("Chilkat.Http");
// To use HTTP Basic authentication:
$http->Login = 'myLogin';
$http->Password = 'myPassword';
$http->BasicAuth = 1;
// Run the test using this URL with the credentials above.
// (Works while httpbin.org keeps the test endpoint available.)
$jsonResponse = $http->quickGetStr('https://httpbin.org/basic-auth/myLogin/myPassword');
if ($http->LastMethodSuccess == 0) {
print $http->LastErrorText . "\n";
exit;
}
print 'Response status code: ' . $http->LastStatus . "\n";
print $jsonResponse . "\n";
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }
?>
|