Sample code for 30+ languages & platforms
PowerBuilder

Example: Http.DownloadAppend method

Demonstrates the DownloadAppend method.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
string ls_TargetPath
oleobject loo_Http
integer li_StatusCode
oleobject loo_Sb
oleobject loo_Fac

li_Success = 0

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Http.KeepResponseBody = 1

// Assume the target file in the local filesystem does not yet exist.
li_Success = loo_Http.DownloadAppend("https://chilkatsoft.com/testData/helloWorld.txt",ls_TargetPath)
li_StatusCode = loo_Http.LastStatus
if li_StatusCode = 0 then
    // Unable to either send the request or get the response.
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    return
end if

// Should be 200.
Write-Debug "Response status code: " + string(li_StatusCode)

// Examine the contents of the file.
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")

loo_Sb.LoadFile(ls_TargetPath,"utf-8")
Write-Debug loo_Sb.GetAsString()

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

// Download another text file and append to the target file.
li_Success = loo_Http.DownloadAppend("https://chilkatsoft.com/testData/this_is_a_test.txt",ls_TargetPath)
li_StatusCode = loo_Http.LastStatus
if li_StatusCode = 0 then
    // Unable to either send the request or get the response.
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Sb
    return
end if

// Should be 200.
Write-Debug "Response status code: " + string(li_StatusCode)

// Examine the contents of the file.
loo_Sb.LoadFile(ls_TargetPath,"utf-8")
Write-Debug loo_Sb.GetAsString()

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

// Delete the local target file.
loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")

loo_Fac.FileDelete(ls_TargetPath)

// Try to download a file that does not exist:
li_Success = loo_Http.DownloadAppend("https://chilkatsoft.com/testData/does_not_exist.txt",ls_TargetPath)
li_StatusCode = loo_Http.LastStatus
if li_StatusCode = 0 then
    // Unable to either send the request or get the response.
    Write-Debug loo_Http.LastErrorText
else
    // We got a response, and we already know it wasn't a 200 success response.
    // It should be a 404 not found.
    Write-Debug "Response status code: " + string(li_StatusCode)
    // Examine the response body.
    Write-Debug "Response body:"
    Write-Debug loo_Http.LastResponseBody
end if



destroy loo_Http
destroy loo_Sb
destroy loo_Fac