C
C
Example: Http.DownloadSb method
See more HTTP Examples
Demonstrates theDownloadSb method.
Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkStringBuilder sb;
int statusCode;
success = FALSE;
http = CkHttp_Create();
CkHttp_putKeepResponseBody(http,TRUE);
sb = CkStringBuilder_Create();
success = CkHttp_DownloadSb(http,"https://chilkatsoft.com/testData/helloWorld.txt","utf-8",sb);
statusCode = CkHttp_getLastStatus(http);
if (success == FALSE) {
if (statusCode == 0) {
// Unable to either send the request or get the response.
printf("%s\n",CkHttp_lastErrorText(http));
}
else {
// We got a response, but the status code was not in the 200s
printf("Response status code: %d\n",statusCode);
// Examine the response body.
printf("Response body:\n");
printf("%s\n",CkHttp_lastResponseBody(http));
}
printf("Download failed.\n");
}
else {
printf("Download success, response status = %d\n",statusCode);
printf("%s\n",CkStringBuilder_getAsString(sb));
}
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sb);
}