Sample code for 30+ languages & platforms
Xbase++

QuickGetBd Example

The QuickGetBd method is called to send a GET request to download a binary target, such as PDF, zip, image file, etc. into a Chilkat BinData object.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oBd
LOCAL nStatusCode
LOCAL oPdf

nSuccess := 0

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

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

oBd := CreateObject("Chilkat.BinData")

//  Download the contents of a PDF file into the bd object.
nSuccess := oHttp:QuickGetBd("https://www.chilkatsoft.com/hello.pdf", oBd)
IF (nSuccess == 0)
    //  This will happen if the response status code was 400 or greater,
    //  or if the request could not be sent, or if no response was received.
    //  
    //  In other words, success will only be 1 if bd contains the desired content at the URL (not an error response).
    nStatusCode := oHttp:LastStatus
    ? "Response status: " + Str(nStatusCode)

    IF (nStatusCode == 0)
        //  There was an error in communications.  
        ? oHttp:LastErrorText
    ELSE
        //  We received a response status code indicating failure.
        //  Examine the response body.
        ? oHttp:LastResponseBody
    ENDIF

    oHttp:destroy()
    oBd:destroy()
    RETURN
ENDIF

//  Load the downloaded PDF into a Chilkat PDF object.
oPdf := CreateObject("Chilkat.Pdf")
nSuccess := oPdf:LoadBd(oBd)
IF (nSuccess == 0)
    ? oPdf:LastErrorText
    oHttp:destroy()
    oBd:destroy()
    oPdf:destroy()
    RETURN
ENDIF

//  ...

? "Success."

oHttp:destroy()
oBd:destroy()
oPdf:destroy()