Sample code for 30+ languages & platforms
Unicode C

Example: Http.ResumeDownload method

Demonstrates the ResumeDownload method.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkFileAccessW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    const wchar_t *localFilePath;
    int statusCode;
    HCkFileAccessW fac;

    success = FALSE;

    http = CkHttpW_Create();
    CkHttpW_putKeepResponseBody(http,TRUE);

    //  To demonstrate resuming a download, we've created a file on the chilkatsoft.com
    //  web server that contains the first 82,379 bytes of the full  279,658 bytes of the hamlet.xml file.

    //  We'll first download the partial file, and pretend it was a previous incomplete attempt to download the entire file.
    localFilePath = L"c:/temp/qa_output/hamlet.xml";
    success = CkHttpW_Download(http,L"https://www.chilkatsoft.com/testData/hamlet_partial.xml",localFilePath);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        return;
    }

    //  Download the remainder of hamlet.xml.
    success = CkHttpW_ResumeDownload(http,L"https://www.chilkatsoft.com/testData/hamlet.xml",localFilePath);
    statusCode = CkHttpW_getLastStatus(http);
    if (success == FALSE) {
        if (statusCode == 0) {
            //  Unable to either send the request or get the response.
            wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        }
        else {
            //  We got a response, but the status code was not in the 200s
            wprintf(L"Response status code: %d\n",statusCode);
            //  Examine the response body.
            wprintf(L"Response body:\n");
            wprintf(L"%s\n",CkHttpW_lastResponseBody(http));
        }

        wprintf(L"Download failed.\n");

    }
    else {
        wprintf(L"Download success, response status = %d\n",statusCode);
    }

    //  The hamlet.xml file should be 279,658 bytes
    fac = CkFileAccessW_Create();
    wprintf(L"size of hamlet.xml: %d\n",CkFileAccessW_FileSize(fac,localFilePath));

    wprintf(L"Success.\n");


    CkHttpW_Dispose(http);
    CkFileAccessW_Dispose(fac);

    }