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

C
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    const char *url;
    HCkHttpRequest req;
    HCkHttpResponse responseObj;
    HCkHttpRequest req2;
    HCkHttpResponse resp;

    success = FALSE;

    http = CkHttp_Create();

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

    req = CkHttpRequest_Create();
    CkHttpRequest_AddParam(req,"company","example");
    CkHttpRequest_AddParam(req,"ip","111.111.111.111");
    CkHttpRequest_AddParam(req,"url","example.com");

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

    responseObj = CkHttp_PostUrlEncoded(http,url,req);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        return;
    }

    //  ...
    //  ...

    CkHttpResponse_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 = CkHttpRequest_Create();
    CkHttpRequest_AddParam(req2,"company","example");
    CkHttpRequest_AddParam(req2,"ip","111.111.111.111");
    CkHttpRequest_AddParam(req2,"url","example.com");

    CkHttpRequest_putHttpVerb(req2,"POST");
    CkHttpRequest_putContentType(req2,"application/x-www-form-urlencoded");

    resp = CkHttpResponse_Create();
    success = CkHttp_HttpReq(http,url,req2,resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkHttpRequest_Dispose(req2);
        CkHttpResponse_Dispose(resp);
        return;
    }

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


    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);
    CkHttpRequest_Dispose(req2);
    CkHttpResponse_Dispose(resp);

    }