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 <C_CkRest.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
BOOL bAutoReconnect;
HCkStringBuilder sbResponse;
const char *responseText;
success = FALSE;
rest = CkRest_Create();
bTls = TRUE;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"example.com",443,bTls,bAutoReconnect);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
// FullRequestNoBodySb sends a request with no body and stores the text response body in a
// StringBuilder.
sbResponse = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/api/items/123",sbResponse);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponse);
return;
}
responseText = CkStringBuilder_getAsString(sbResponse);
if (CkStringBuilder_getLastMethodSuccess(sbResponse) == FALSE) {
printf("%s\n",CkStringBuilder_lastErrorText(sbResponse));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponse);
return;
}
printf("%s\n",responseText);
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponse);
}