Sample code for 30+ languages & platforms
Unicode C++

Send a REST Request using StringBuilder Bodies

See more REST Examples

Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.

Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkRestW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkRestW rest;
    bool bTls = true;
    bool bAutoReconnect = true;
    success = rest.Connect(L"example.com",443,bTls,bAutoReconnect);
    if (success == false) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    //  FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
    //  response body in a second StringBuilder.  This avoids extra string conversions for large bodies.
    CkStringBuilderW sbRequest;
    sbRequest.Append(L"{ \"query\": \"chilkat\" }");

    rest.AddHeader(L"Content-Type",L"application/json");

    CkStringBuilderW sbResponse;
    success = rest.FullRequestSb(L"POST",L"/api/search",sbRequest,sbResponse);
    if (success == false) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    const wchar_t *responseText = sbResponse.getAsString();
    if (sbResponse.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",sbResponse.lastErrorText());
        return;
    }

    wprintf(L"%s\n",responseText);
    }