(C++) Example: Http.DownloadSb method
Demonstrates the DownloadSb method.
#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";
}
}
|