PHP ActiveX
PHP ActiveX
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat PHP ActiveX Downloads
<?php
$success = 0;
$rest = new COM("Chilkat.Rest");
$bTls = 1;
$bAutoReconnect = 1;
$success = $rest->Connect('example.com',443,$bTls,$bAutoReconnect);
if ($success == 0) {
print $rest->LastErrorText . "\n";
exit;
}
// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder. This avoids extra string conversions for large bodies.
$sbRequest = new COM("Chilkat.StringBuilder");
$sbRequest->Append('{ \'query\': \'chilkat\' }');
$rest->AddHeader('Content-Type','application/json');
$sbResponse = new COM("Chilkat.StringBuilder");
$success = $rest->FullRequestSb('POST','/api/search',$sbRequest,$sbResponse);
if ($success == 0) {
print $rest->LastErrorText . "\n";
exit;
}
$responseText = $sbResponse->getAsString();
if ($sbResponse->LastMethodSuccess == 0) {
print $sbResponse->LastErrorText . "\n";
exit;
}
print $responseText . "\n";
?>