PHP
Chilkat2 PHP
Example: Http.DownloadSb method
See more HTTP Examples
Demonstrates theDownloadSb method.
Chilkat PHP Downloads
<?php
use Chilkat2\Http;
use Chilkat2\StringBuilder;
$success = false;
$http = new Http();
$http->KeepResponseBody = true;
$sb = new StringBuilder();
try {
$http->DownloadSb('https://chilkatsoft.com/testData/helloWorld.txt', 'utf-8', $sb);
$success = true;
} catch (\Chilkat2\Exception $e) {
$success = false;
}
$statusCode = $http->LastStatus;
if (!$success) {
if ($statusCode == 0) {
// Unable to either send the request or get the response.
echo $http->LastErrorText, "\n";
} else {
// We got a response, but the status code was not in the 200s
echo 'Response status code: ', $statusCode, "\n";
// Examine the response body.
echo "Response body:\n";
echo $http->LastResponseBody, "\n";
}
echo "Download failed.\n";
} else {
echo 'Download success, response status = ', $statusCode, "\n";
echo $sb->GetAsString(), "\n";
}