Xbase++
Xbase++
Download a Binary REST Response into BinData
See more REST Examples
Demonstrates Rest.FullRequestNoBodyBd, which sends a request with no body and stores the binary response body in a BinData.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. This method is appropriate when the response is binary, such as an image or file download, allowing the received bytes to be saved or processed directly.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oBdResponse
LOCAL nBSaved
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// The file paths are relative to the application's current working directory. Absolute paths
// may also be used. Supply the paths appropriate to your own environment.
// FullRequestNoBodyBd sends a request with no body and stores the binary response body in a
// BinData. This is appropriate when the response is binary, such as an image or file download.
oBdResponse := CreateObject("Chilkat.BinData")
nSuccess := oRest:FullRequestNoBodyBd("GET", "/api/images/1", oBdResponse)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oBdResponse:destroy()
RETURN
ENDIF
nBSaved := oBdResponse:WriteFile("qa_output/image.png")
IF (nBSaved != 1)
? "Failed to save the response body."
oRest:destroy()
oBdResponse:destroy()
RETURN
ENDIF
? "Downloaded " + Str(oBdResponse:NumBytes) + " bytes."
oRest:destroy()
oBdResponse:destroy()