Visual FoxPro
Visual FoxPro
Send a REST Request with a Binary Body
See more REST Examples
Demonstrates Rest.FullRequestBd, which sends a complete request whose binary body is read from a BinData and stores the text response body in a StringBuilder.
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. FullRequestBd is used when the request payload is binary, such as an image or other file, while the response is textual (for example a JSON acknowledgement).
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loBdRequest
LOCAL lnBLoaded
LOCAL loSbResponse
LOCAL lcResponseText
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.
* FullRequestBd sends a request whose binary body is read from a BinData and stores the text
* response body in a StringBuilder.
loBdRequest = CreateObject('Chilkat.BinData')
lnBLoaded = loBdRequest.LoadFile("qa_data/image.png")
IF (lnBLoaded <> 1) THEN
? "Failed to load the request body file."
RELEASE loRest
RELEASE loBdRequest
CANCEL
ENDIF
loRest.AddHeader("Content-Type","image/png")
loSbResponse = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestBd("PUT","/api/images/1",loBdRequest,loSbResponse)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loBdRequest
RELEASE loSbResponse
CANCEL
ENDIF
lcResponseText = loSbResponse.GetAsString()
IF (loSbResponse.LastMethodSuccess = 0) THEN
? loSbResponse.LastErrorText
RELEASE loRest
RELEASE loBdRequest
RELEASE loSbResponse
CANCEL
ENDIF
? lcResponseText
RELEASE loRest
RELEASE loBdRequest
RELEASE loSbResponse