Unicode C
Unicode C
Example: Http.ResumeDownloadBd method
Demonstrates theResumeDownloadBd method.
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkBinDataW bd;
int statusCode;
success = FALSE;
http = CkHttpW_Create();
CkHttpW_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 = CkBinDataW_Create();
success = CkHttpW_DownloadBd(http,L"https://www.chilkatsoft.com/testData/hamlet_partial.xml",bd);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkBinDataW_Dispose(bd);
return;
}
// Download the remainder of hamlet.xml.
success = CkHttpW_ResumeDownloadBd(http,L"https://www.chilkatsoft.com/testData/hamlet.xml",bd);
statusCode = CkHttpW_getLastStatus(http);
if (success == FALSE) {
if (statusCode == 0) {
// Unable to either send the request or get the response.
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
}
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",CkHttpW_lastResponseBody(http));
}
wprintf(L"Download failed.\n");
}
else {
wprintf(L"Download success, response status = %d\n",statusCode);
}
// The hamlet.xml file should be 279,658 bytes
wprintf(L"size of hamlet.xml: %d\n",CkBinDataW_getNumBytes(bd));
wprintf(L"Success.\n");
CkHttpW_Dispose(http);
CkBinDataW_Dispose(bd);
}