Sample code for 30+ languages & platforms
Xbase++

Example: Http.DownloadAppend method

Demonstrates the DownloadAppend method.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cTargetPath
LOCAL oHttp
LOCAL nStatusCode
LOCAL oSb
LOCAL oFac

nSuccess := 0

cTargetPath := "c:/temp/qa_output/download.txt"

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

//  Assume the target file in the local filesystem does not yet exist.
nSuccess := oHttp:DownloadAppend("https://chilkatsoft.com/testData/helloWorld.txt", cTargetPath)
nStatusCode := oHttp:LastStatus
IF (nStatusCode == 0)
    //  Unable to either send the request or get the response.
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

//  Should be 200.
? "Response status code: " + Str(nStatusCode)

//  Examine the contents of the file.
oSb := CreateObject("Chilkat.StringBuilder")
oSb:LoadFile(cTargetPath, "utf-8")
? oSb:GetAsString()

//  Output: 
//  Response status code: 200
//  Hello World!

//  Download another text file and append to the target file.
nSuccess := oHttp:DownloadAppend("https://chilkatsoft.com/testData/this_is_a_test.txt", cTargetPath)
nStatusCode := oHttp:LastStatus
IF (nStatusCode == 0)
    //  Unable to either send the request or get the response.
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSb:destroy()
    RETURN
ENDIF

//  Should be 200.
? "Response status code: " + Str(nStatusCode)

//  Examine the contents of the file.
oSb:LoadFile(cTargetPath, "utf-8")
? oSb:GetAsString()

//  Output:
//  Response status code: 200
//  Hello World!This is a Test.

//  Delete the local target file.
oFac := CreateObject("Chilkat.FileAccess")
oFac:FileDelete(cTargetPath)

//  Try to download a file that does not exist:
nSuccess := oHttp:DownloadAppend("https://chilkatsoft.com/testData/does_not_exist.txt", cTargetPath)
nStatusCode := oHttp:LastStatus
IF (nStatusCode == 0)
    //  Unable to either send the request or get the response.
    ? oHttp:LastErrorText
ELSE
    //  We got a response, and we already know it wasn't a 200 success response.
    //  It should be a 404 not found.
    ? "Response status code: " + Str(nStatusCode)
    //  Examine the response body.
    ? "Response body:"
    ? oHttp:LastResponseBody
ENDIF

oHttp:destroy()
oSb:destroy()
oFac:destroy()