C
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 C Downloads
#include <C_CkRest.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
BOOL bAutoReconnect;
const char *responseText;
success = FALSE;
rest = CkRest_Create();
bTls = TRUE;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"example.com",443,bTls,bAutoReconnect);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
// The application/x-www-form-urlencoded body is built from the query parameters added to the object.
CkRest_AddQueryParam(rest,"username","alice");
CkRest_AddQueryParam(rest,"action","login");
// Send the form-url-encoded request. The parameters become the request body rather than the URL
// query string.
responseText = CkRest_fullRequestFormUrlEncoded(rest,"POST","/api/login");
if (CkRest_getLastMethodSuccess(rest) == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
printf("%s\n",responseText);
CkRest_Dispose(rest);
}