HTTP Download

Back to HTTP Tutorial Index

Chilkat defines a "download" as an HTTP (or HTTPS) GET request, where the body of the response contains the data of the file to be saved. It can be a file of any type, such as a .zip, .pdf, .txt, .json, .xml, .doc, .xls, .ppt, etc.

For example:

GET /9.5.0.95/chilkatext-9.5.0-linux-x64-gcc.tar.gz HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: chilkatdownload.com
Accept-Encoding: gzip, deflate
Connection: keep-alive

The Chilkat Download* Methods

The Chilkat Http class provides "download" methods for retrieving the contents of the data at a URL. For example:

  • Download: GET's data at a URL and streams directly to a local file.
  • DownloadBd: GET's data at a URL and returns a Chilkat BinData object containing the data. This is good for non-huge binary files that can fit in memory, where you don't wish to create a local file.
  • DownloadSb: GET's data at a URL and returns a Chilkat StringBuilder object containing the data. This is good for non-huge text files that can fit in memory, where you don't wish to create a local file.
  • DownloadHash: GET's data at a URL and returns only the digest of the data, such as SHA256, SHA1, MD5, SHA512, etc. You can specify the hash algorithm. The data is discarded, and only the hash is returned. This is good for checking the digest (hash) of an online file.
  • DownloadAppend: The same as the Download method, but appends to the local file.

Download Methods Return True/False

The download methods return a boolean (or integer having value 0 or 1 in some programming languages) to indicate success or failure. Success is when the HTTP response code is in the 200's (typically the response code for a download should be exactly 200). If the download fails (i.e. the HTTP response code does not indicate success by equalling 200 (or in the 200's)), then the local file is NOT created, and the data is not returned in the BinData or StringBuilder objects (depending on the function). Instead, the response body, if any, must have contained an error response, which would typically be HTML. The error response is available in the Http.LastResponseBody property, but ONLY IF the Http.KeepResponseBody property is set, and Chilkat will limit the error response size to 64K by truncating if needed. It's highly unlikely that an error response will be larger.