Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkRestW.h>
void ChilkatSample(void)
{
bool success = false;
CkRestW rest;
bool bTls = true;
bool bAutoReconnect = true;
success = rest.Connect(L"example.com",443,bTls,bAutoReconnect);
if (success == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// The application/x-www-form-urlencoded body is built from the query parameters added to the object.
rest.AddQueryParam(L"username",L"alice");
rest.AddQueryParam(L"action",L"login");
// Send the form-url-encoded request. The parameters become the request body rather than the URL
// query string.
const wchar_t *responseText = rest.fullRequestFormUrlEncoded(L"POST",L"/api/login");
if (rest.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
wprintf(L"%s\n",responseText);
}