Sample code for 30+ languages & platforms
Unicode C

Transition from Http.PostUrlEncoded to Http.HttpReq

Provides instructions for replacing deprecated PostUrlEncoded method calls with HttpReq.

Sends the following raw HTTP request:

POST /echoPost.asp HTTP/1.1
Host: www.chilkatsoft.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 50

company=example&ip=111.111.111.111&url=example.com

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 *url;
    HCkHttpRequestW req;
    HCkHttpResponseW responseObj;
    HCkHttpRequestW req2;
    HCkHttpResponseW resp;

    success = FALSE;

    http = CkHttpW_Create();

    url = L"https://www.chilkatsoft.com/echoPost.asp";

    req = CkHttpRequestW_Create();
    CkHttpRequestW_AddParam(req,L"company",L"example");
    CkHttpRequestW_AddParam(req,L"ip",L"111.111.111.111");
    CkHttpRequestW_AddParam(req,L"url",L"example.com");

    //  ------------------------------------------------------------------------
    //  The PostUrlEncoded method is deprecated:

    responseObj = CkHttpW_PostUrlEncoded(http,url,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 HttpReq.
    //  Your application creates a new, empty HttpResponse object which is passed 
    //  in the last argument and filled upon success.

    req2 = CkHttpRequestW_Create();
    CkHttpRequestW_AddParam(req2,L"company",L"example");
    CkHttpRequestW_AddParam(req2,L"ip",L"111.111.111.111");
    CkHttpRequestW_AddParam(req2,L"url",L"example.com");

    CkHttpRequestW_putHttpVerb(req2,L"POST");
    CkHttpRequestW_putContentType(req2,L"application/x-www-form-urlencoded");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpReq(http,url,req2,resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkHttpRequestW_Dispose(req2);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    //  Results are contained in the HTTP response object...


    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkHttpRequestW_Dispose(req2);
    CkHttpResponseW_Dispose(resp);

    }