(Unicode C++) Example: Http.DownloadSb method
Demonstrates the DownloadSb method.
#include <CkHttpW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
CkHttpW http;
http.put_KeepResponseBody(true);
CkStringBuilderW sb;
success = http.DownloadSb(L"https://chilkatsoft.com/testData/helloWorld.txt",L"utf-8",sb);
int statusCode = http.get_LastStatus();
if (success == false) {
if (statusCode == 0) {
// Unable to either send the request or get the response.
wprintf(L"%s\n",http.lastErrorText());
}
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",http.lastResponseBody());
}
wprintf(L"Download failed.\n");
}
else {
wprintf(L"Download success, response status = %d\n",statusCode);
wprintf(L"%s\n",sb.getAsString());
}
}
|