C
C
Example: Http.ResumeDownload method
Demonstrates theResumeDownload method.
Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkFileAccess.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
const char *localFilePath;
int statusCode;
HCkFileAccess fac;
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.
localFilePath = "c:/temp/qa_output/hamlet.xml";
success = CkHttp_Download(http,"https://www.chilkatsoft.com/testData/hamlet_partial.xml",localFilePath);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
return;
}
// Download the remainder of hamlet.xml.
success = CkHttp_ResumeDownload(http,"https://www.chilkatsoft.com/testData/hamlet.xml",localFilePath);
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
fac = CkFileAccess_Create();
printf("size of hamlet.xml: %d\n",CkFileAccess_FileSize(fac,localFilePath));
printf("Success.\n");
CkHttp_Dispose(http);
CkFileAccess_Dispose(fac);
}