C
C
Example: Http.ResumeDownloadBd method
Demonstrates theResumeDownloadBd method.
Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkBinData.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkBinData bd;
int statusCode;
success = FALSE;
http = CkHttp_Create();
CkHttp_putKeepResponseBody(http,TRUE);
// To demonstrate resuming a download, we've created a file on the chilkatsoft.com
// web server that contains the first 82,379 bytes of the full 279,658 bytes of the hamlet.xml file.
// We'll first download the partial file, and pretend it was a previous incomplete attempt to download the entire file.
bd = CkBinData_Create();
success = CkHttp_DownloadBd(http,"https://www.chilkatsoft.com/testData/hamlet_partial.xml",bd);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkBinData_Dispose(bd);
return;
}
// Download the remainder of hamlet.xml.
success = CkHttp_ResumeDownloadBd(http,"https://www.chilkatsoft.com/testData/hamlet.xml",bd);
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);
}
// The hamlet.xml file should be 279,658 bytes
printf("size of hamlet.xml: %d\n",CkBinData_getNumBytes(bd));
printf("Success.\n");
CkHttp_Dispose(http);
CkBinData_Dispose(bd);
}