Sample code for 30+ languages & platforms
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

Unicode C
#include <C_CkRestW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    BOOL bAutoReconnect;
    const wchar_t *responseText;

    success = FALSE;

    rest = CkRestW_Create();
    bTls = TRUE;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"example.com",443,bTls,bAutoReconnect);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

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

    //  Send the form-url-encoded request.  The parameters become the request body rather than the URL
    //  query string.
    responseText = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/api/login");
    if (CkRestW_getLastMethodSuccess(rest) == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    wprintf(L"%s\n",responseText);


    CkRestW_Dispose(rest);

    }