Sample code for 30+ languages & platforms
Unicode C

HTTP POST JSON

See more HTTP Examples

Demonstrates how to send a JSON POST and get the JSON response.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    const wchar_t *jsonText;
    HCkHttpResponseW resp;

    success = FALSE;

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code

    http = CkHttpW_Create();

    jsonText = L"{\"user\":\"doctoravatar@penzance.com\",\"forecast\":7,\"t\":\"vlIj\",\"zip\":94089}";

    // IMPORTANT: Make sure to change the URL, JSON text,
    // and other data items to your own values.  The URL used
    // in this example will not actually work.

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpStr(http,L"POST",L"https://json.penzance.org/request",jsonText,L"utf-8",L"application/json",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    // Display the JSON response.
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));


    CkHttpW_Dispose(http);
    CkHttpResponseW_Dispose(resp);

    }