Sample code for 30+ languages & platforms
Perl Requires Chilkat v11.0.0+

HTTP POST with Binary Data in Request Body

See more HTTP Examples

Do an HTTPS POST with a binary request body.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

#  This example assumes the Chilkat API to have been previously unlocked.
#  See Global Unlock Sample for sample code.

$http = chilkat::CkHttp->new();

$fac = chilkat::CkFileAccess->new();

$reqBody = chilkat::CkByteData->new();
$success = $fac->ReadEntireFile("qa_data/pdf/helloWorld.pdf",$reqBody);

$resp = chilkat::CkHttpResponse->new();
$success = $http->HttpBinary("POST","https://example.com/something",$reqBody,"application/pdf",$resp);
if ($success == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

$responseStatusCode = $resp->get_StatusCode();
print "Status code: " . $responseStatusCode . "\r\n";

#  For example, if the response is XML, JSON, HTML, etc.
print "response body:" . "\r\n";
print $resp->bodyStr() . "\r\n";