Sample code for 30+ languages & platforms
Perl

Send a Form-URL-Encoded REST Request

See more REST Examples

Demonstrates Rest.FullRequestFormUrlEncoded, which sends an application/x-www-form-urlencoded request. The body is built from the query parameters added to the object, and the response body is returned as text.

Background. For a form-url-encoded request the accumulated parameters become the request body rather than the URL query string. This matches the encoding used by HTML form POSTs.

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;
}

#  The application/x-www-form-urlencoded body is built from the query parameters added to the object.
$rest->AddQueryParam("username","alice");
$rest->AddQueryParam("action","login");

#  Send the form-url-encoded request.  The parameters become the request body rather than the URL
#  query string.
$responseText = $rest->fullRequestFormUrlEncoded("POST","/api/login");
if ($rest->get_LastMethodSuccess() == 0) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

print $responseText . "\r\n";