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