Sample code for 30+ languages & platforms
C

Transition from Http.PFile to Http.HttpFile

Provides instructions for replacing deprecated PFile method calls with HttpFile.

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 *localFilePath;
    const char *contentType;
    HCkHttpResponse responseObj;
    HCkHttpResponse responseOut;

    success = FALSE;

    http = CkHttp_Create();

    verb = "POST";
    url = "https://example.com/";
    localFilePath = "c:/temp/requestBodyContent.dat";
    contentType = "application/octet-stream";

    //  ------------------------------------------------------------------------
    //  The PFile method is deprecated:

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

    //  ...
    //  ...

    CkHttpResponse_Dispose(responseObj);

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

    responseOut = CkHttpResponse_Create();
    success = CkHttp_HttpFile(http,verb,url,localFilePath,contentType,responseOut);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(responseOut);
        return;
    }



    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(responseOut);

    }