Perl Requires Chilkat v11.2.0+
Chilkat2 Perl
Example: Http.SetAuthTokenSb method
Demonstrates theSetAuthTokenSb method.
Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $success = 0;
my $http = Chilkat2::Http->new;
my $oauth2_access_token = 'ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ';
my $sbAccessToken = Chilkat2::StringBuilder->new;
$sbAccessToken->Append($oauth2_access_token);
# Causes the "Authorization: Bearer <access_token>" header to be added to all HTTP requests.
$http->SetAuthTokenSb($sbAccessToken);
my $responseText = $http->QuickGetStr('https://chilkatsoft.com/helloWorld.txt');
if (!$http->LastMethodSuccess) {
print $http->LastErrorText, "\n";
exit;
}
# See the HTTP request header that was sent.
print $http->LastHeader, "\n";
# Output:
#
# GET /helloWorld.txt HTTP/1.1
# Host: chilkatsoft.com
# Accept: */*
# Accept-Encoding: gzip
# Authorization: Bearer ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ
# Note: The information that should be kept secret in the Authorization header
# will be redacted. Thus, the LastHeader property will show the following:
# Authorization: Bearer ****