Sample code for 30+ languages & platforms
C

Transition from Http.PutText to Http.HttpStr

Provides instructions for replacing deprecated PutText 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 *verb;
    const char *url;
    const char *textData;
    const char *charset;
    const char *contentType;
    const char *responseBody;
    HCkHttpResponse responseOut;

    success = FALSE;

    http = CkHttp_Create();

    verb = "PUT";
    url = "https://example.com/";
    textData = "This is the HTTP request body";
    charset = "utf-8";
    contentType = "text/plain";

    //  ------------------------------------------------------------------------
    //  The PutText method is deprecated:

    responseBody = CkHttp_putText(http,url,textData,charset,contentType,FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    //  ...
    //  ...

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

    responseBody = CkHttpResponse_bodyStr(responseOut);


    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(responseOut);

    }