Sample code for 30+ languages & platforms
C

Transition from Http.PostJson2 to Http.HttpStr

Provides instructions for replacing deprecated PostJson2 method calls with HttpStr.

Chilkat C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    const char *url;
    const char *contentType;
    const char *jsonText;
    HCkHttpResponse responseObj;
    HCkHttpResponse responseOut;

    success = FALSE;

    http = CkHttp_Create();

    url = "https://example.com/something";
    contentType = "application/json";
    jsonText = "{ ... }";

    //  ------------------------------------------------------------------------
    //  The PostJson2 method is deprecated:

    responseObj = CkHttp_PostJson2(http,url,contentType,jsonText);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    //  ...
    //  ...

    CkHttpResponse_Dispose(responseObj);

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

    responseOut = CkHttpResponse_Create();
    success = CkHttp_HttpStr(http,"POST",url,jsonText,"utf-8",contentType,responseOut);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(responseOut);
        return;
    }



    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(responseOut);

    }