Sample code for 30+ languages & platforms
PureBasic

Example: Http.ResumeDownloadBd method

Demonstrates the ResumeDownloadBd method.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkBinData.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    CkHttp::setCkKeepResponseBody(http, 1)

    ; 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.i = CkBinData::ckCreate()
    If bd.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckDownloadBd(http,"https://www.chilkatsoft.com/testData/hamlet_partial.xml",bd)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkBinData::ckDispose(bd)
        ProcedureReturn
    EndIf

    ; Download the remainder of hamlet.xml.
    success = CkHttp::ckResumeDownloadBd(http,"https://www.chilkatsoft.com/testData/hamlet.xml",bd)
    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

    ; The hamlet.xml file should be 279,658 bytes
    Debug "size of hamlet.xml: " + Str(CkBinData::ckNumBytes(bd))

    Debug "Success."


    CkHttp::ckDispose(http)
    CkBinData::ckDispose(bd)


    ProcedureReturn
EndProcedure