Sample code for 30+ languages & platforms
PHP ActiveX

HTTP POST with Binary Data in Request Body

See more HTTP Examples

Do an HTTPS POST with a binary request body.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

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

$http = new COM("Chilkat.Http");

$fac = new COM("Chilkat.FileAccess");

$reqBody = $fac->ReadEntireFile('qa_data/pdf/helloWorld.pdf');

$resp = new COM("Chilkat.HttpResponse");
$success = $http->HttpBinary('POST','https://example.com/something',$reqBody,'application/pdf',$resp);
if ($success == 0) {
    print $http->LastErrorText . "\n";
    exit;
}

$responseStatusCode = $resp->StatusCode;
print 'Status code: ' . $responseStatusCode . "\n";

// For example, if the response is XML, JSON, HTML, etc.
print 'response body:' . "\n";
print $resp->BodyStr . "\n";

?>