C++
C++
Send a Bodyless REST Request into a StringBuilder
See more REST Examples
Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.
Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.
Chilkat C++ Downloads
#include <CkRest.h>
#include <CkStringBuilder.h>
void ChilkatSample(void)
{
bool success = false;
CkRest rest;
bool bTls = true;
bool bAutoReconnect = true;
success = rest.Connect("example.com",443,bTls,bAutoReconnect);
if (success == false) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
// FullRequestNoBodySb sends a request with no body and stores the text response body in a
// StringBuilder.
CkStringBuilder sbResponse;
success = rest.FullRequestNoBodySb("GET","/api/items/123",sbResponse);
if (success == false) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
const char *responseText = sbResponse.getAsString();
if (sbResponse.get_LastMethodSuccess() == false) {
std::cout << sbResponse.lastErrorText() << "\r\n";
return;
}
std::cout << responseText << "\r\n";
}