Sample code for 30+ languages & platforms
Xbase++

HTTP Download any Type of File (binary or text)

See more HTTP Examples

The Download method can download any file type, whether binary (e.g., .zip, .pdf) or text (.xml, .txt), without distinction. It streams the file byte-for-byte from the web server exactly as received. This same process applies to web pages: providing a URL typically viewed in a browser downloads the server's delivered HTML to a file.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cLocalFilePath
LOCAL nStatusCode

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")
oHttp:KeepResponseBody := 1

//  Download a .zip
cLocalFilePath := "/temp/hamlet.zip"
nSuccess := oHttp:Download("https://www.chilkatsoft.com/hamlet.zip", cLocalFilePath)
nStatusCode := oHttp:LastStatus
IF (nSuccess == 0)
    IF (nStatusCode == 0)
        //  Unable to either send the request or get the response.
        ? oHttp:LastErrorText
    ELSE
        //  We got a response, but the status code was not in the 200s
        ? "Response status code: " + Str(nStatusCode)
        //  Examine the response body.
        ? "Response body:"
        ? oHttp:LastResponseBody
    ENDIF

    ? "Download failed."

ELSE
    ? "Download success, response status = " + Str(nStatusCode)
ENDIF

//  Download an XML file:
cLocalFilePath := "/temp/hamlet.xml"
nSuccess := oHttp:Download("https://www.chilkatsoft.com/hamlet.xml", cLocalFilePath)
//  ...
//  Check for errors in the same way as shown above..
//  ...

? "OK!"

oHttp:destroy()