Sample code for 30+ languages & platforms
C++

Example: Http.DownloadSb method

See more HTTP Examples

Demonstrates the DownloadSb method.

Chilkat C++ Downloads

C++
#include <CkHttp.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkHttp http;
    http.put_KeepResponseBody(true);

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

    int statusCode = http.get_LastStatus();
    if (success == false) {
        if (statusCode == 0) {
            //  Unable to either send the request or get the response.
            std::cout << http.lastErrorText() << "\r\n";
        }
        else {
            //  We got a response, but the status code was not in the 200s
            std::cout << "Response status code: " << statusCode << "\r\n";
            //  Examine the response body.
            std::cout << "Response body:" << "\r\n";
            std::cout << http.lastResponseBody() << "\r\n";
        }

        std::cout << "Download failed." << "\r\n";

    }
    else {
        std::cout << "Download success, response status = " << statusCode << "\r\n";
        std::cout << sb.getAsString() << "\r\n";
    }
    }