Sample code for 30+ languages & platforms
PureBasic

Example: Http.ResumeDownload method

Demonstrates the ResumeDownload method.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkFileAccess.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.
    localFilePath.s = "c:/temp/qa_output/hamlet.xml"
    success = CkHttp::ckDownload(http,"https://www.chilkatsoft.com/testData/hamlet_partial.xml",localFilePath)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

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

    ; The hamlet.xml file should be 279,658 bytes
    fac.i = CkFileAccess::ckCreate()
    If fac.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    Debug "size of hamlet.xml: " + Str(CkFileAccess::ckFileSize(fac,localFilePath))

    Debug "Success."


    CkHttp::ckDispose(http)
    CkFileAccess::ckDispose(fac)


    ProcedureReturn
EndProcedure