PHP
Chilkat2 PHP
POST application/x-www-form-urlencoded using REST API
See more REST Examples
Demonstrates how to send a POST with query params (x-www-form-urlencoded) using the Chilkat REST object.Chilkat PHP Downloads
<?php
use Chilkat2\Rest;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$rest = new Rest();
// This example will send to https://www.chilkatsoft.com/echoPost.asp
// Make the initial connection (without sending a request yet).
$bTls = true;
$port = 443;
$bAutoReconnect = true;
try {
$rest->Connect('www.chilkatsoft.com', $port, $bTls, $bAutoReconnect);
// Provide query params.
$rest->AddQueryParam('firstName', 'John');
$rest->AddQueryParam('lastName', 'Doe');
$rest->AddQueryParam('company', 'Bisco Bits Ltd.');
$responseStr = $rest->FullRequestFormUrlEncoded('POST', '/echoPost.asp');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// When successful, the response status code will equal 200.
if ($rest->ResponseStatusCode != 200) {
// Examine the request/response to see what happened.
echo 'response status code = ', $rest->ResponseStatusCode, "\n";
echo 'response status text = ', $rest->ResponseStatusText, "\n";
echo 'response header: ', $rest->ResponseHeader, "\n";
echo 'response body (if any): ', $responseStr, "\n";
echo "---\n";
echo 'LastRequestStartLine: ', $rest->LastRequestStartLine, "\n";
echo 'LastRequestHeader: ', $rest->LastRequestHeader, "\n";
exit;
}
echo $responseStr, "\n";
echo "Success.\n";