Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loBdResponse
LOCAL lnBSaved
lnSuccess = 0
loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
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.
loBdResponse = CreateObject('Chilkat.BinData')
lnSuccess = loRest.FullRequestNoBodyBd("GET","/api/images/1",loBdResponse)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loBdResponse
CANCEL
ENDIF
lnBSaved = loBdResponse.WriteFile("qa_output/image.png")
IF (lnBSaved <> 1) THEN
? "Failed to save the response body."
RELEASE loRest
RELEASE loBdResponse
CANCEL
ENDIF
? "Downloaded " + STR(loBdResponse.NumBytes) + " bytes."
RELEASE loRest
RELEASE loBdResponse