Sample code for 30+ languages & platforms
C

Transition from Http.PostXml to Http.HttpStr

Provides instructions for replacing deprecated PostXml 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 *requestBodyXml;
    const char *charset;
    HCkHttpResponse responseObj;
    HCkHttpResponse responseOut;

    success = FALSE;

    http = CkHttp_Create();

    url = "https://example.com/something";
    requestBodyXml = "<something>...</something>";
    charset = "utf-8";

    //  ------------------------------------------------------------------------
    //  The PostXml method is deprecated:

    responseObj = CkHttp_PostXml(http,url,requestBodyXml,charset);
    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,requestBodyXml,charset,"application/xml",responseOut);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(responseOut);
        return;
    }



    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(responseOut);

    }