Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttp::setCkKeepResponseBody(http, 1)

    ; Download a .zip
    localFilePath.s = "/temp/hamlet.zip"
    success = CkHttp::ckDownload(http,"https://www.chilkatsoft.com/hamlet.zip",localFilePath)
    statusCode.i = CkHttp::ckLastStatus(http)
    If success = 0
        If statusCode = 0
            ; Unable to either send the request or get the response.
            Debug CkHttp::ckLastErrorText(http)
        Else
            ; We got a response, but the status code was not in the 200s
            Debug "Response status code: " + Str(statusCode)
            ; Examine the response body.
            Debug "Response body:"
            Debug CkHttp::ckLastResponseBody(http)
        EndIf

        Debug "Download failed."

    Else
        Debug "Download success, response status = " + Str(statusCode)
    EndIf

    ; Download an XML file:
    localFilePath = "/temp/hamlet.xml"
    success = CkHttp::ckDownload(http,"https://www.chilkatsoft.com/hamlet.xml",localFilePath)
    ; ...
    ; Check for errors in the same way as shown above..
    ; ...

    Debug "OK!"


    CkHttp::ckDispose(http)


    ProcedureReturn
EndProcedure