Sample code for 30+ languages & platforms
Unicode C

Transition from Http.SynchronousRequest to Http.HttpSReq

Provides instructions for replacing deprecated SynchronousRequest method calls with HttpSReq.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    const wchar_t *domain;
    int port;
    int tls;
    HCkHttpRequestW req;
    HCkHttpResponseW responseObj;
    HCkHttpResponseW responseOut;

    success = FALSE;

    http = CkHttpW_Create();

    domain = L"example.com";
    port = 443;
    tls = TRUE;

    req = CkHttpRequestW_Create();
    CkHttpRequestW_putHttpVerb(req,L"POST");
    CkHttpRequestW_putPath(req,L"/some/path");
    CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded");
    CkHttpRequestW_AddParam(req,L"firstName",L"Matt");
    CkHttpRequestW_AddParam(req,L"lastName",L"Smith");

    //  ------------------------------------------------------------------------
    //  The SynchronousRequest method is deprecated:

    responseObj = CkHttpW_SynchronousRequest(http,domain,port,tls,req);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        return;
    }

    //  ...
    //  ...

    CkHttpResponseW_Dispose(responseObj);

    //  ------------------------------------------------------------------------
    //  Do the equivalent using HttpSReq.
    //  Your application creates a new, empty HttpResponse object which is passed 
    //  in the last argument and filled upon success.

    responseOut = CkHttpResponseW_Create();
    success = CkHttpW_HttpSReq(http,domain,port,tls,req,responseOut);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkHttpResponseW_Dispose(responseOut);
        return;
    }



    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkHttpResponseW_Dispose(responseOut);

    }