Sample code for 30+ languages & platforms
Unicode C

Example: Http.DownloadSb method

See more HTTP Examples

Demonstrates the DownloadSb method.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkStringBuilderW sb;
    int statusCode;

    success = FALSE;

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

    sb = CkStringBuilderW_Create();
    success = CkHttpW_DownloadSb(http,L"https://chilkatsoft.com/testData/helloWorld.txt",L"utf-8",sb);

    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);
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sb));
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sb);

    }