Sample code for 30+ languages & platforms
Perl

Configure HTTP Basic Authentication with SecureString

See more REST Examples

Demonstrates Rest.SetAuthBasicSecure, which configures HTTP Basic authentication using SecureString objects instead of plaintext strings.

Background. A SecureString keeps sensitive values encrypted in memory, reducing the window in which credentials appear as readable plaintext. This is otherwise equivalent to SetAuthBasic.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

$rest = chilkat::CkRest->new();
$bTls = 1;
$bAutoReconnect = 1;
$success = $rest->Connect("example.com",443,$bTls,$bAutoReconnect);
if ($success == 0) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

#  SetAuthBasicSecure configures HTTP Basic authentication using SecureString objects, which keep
#  the credentials encrypted in memory.
#  Normally you would not hard-code secrets in source.  You should instead obtain them from an
#  interactive prompt, environment variable, or a secrets vault.
$ssUsername = chilkat::CkSecureString->new();
$ssUsername->Append("myUsername");
$ssPassword = chilkat::CkSecureString->new();
$ssPassword->Append("myPassword");

$success = $rest->SetAuthBasicSecure($ssUsername,$ssPassword);
if ($success == 0) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

$responseText = $rest->fullRequestNoBody("GET","/api/protected");
if ($rest->get_LastMethodSuccess() == 0) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

print $responseText . "\r\n";