Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
loRest = createobject("CkRest")
llBTls = .T.
llBAutoReconnect = .T.
llSuccess = loRest.Connect("example.com",443,llBTls,llBAutoReconnect)
if (llSuccess = .F.) then
? loRest.LastErrorText
release loRest
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.
// FullRequestBd sends a request whose binary body is read from a BinData and stores the text
// response body in a StringBuilder.
loBdRequest = createobject("CkBinData")
llBLoaded = loBdRequest.LoadFile("qa_data/image.png")
if (llBLoaded <> .T.) then
? "Failed to load the request body file."
release loRest
release loBdRequest
return
endif
loRest.AddHeader("Content-Type","image/png")
loSbResponse = createobject("CkStringBuilder")
llSuccess = loRest.FullRequestBd("PUT","/api/images/1",loBdRequest,loSbResponse)
if (llSuccess = .F.) then
? loRest.LastErrorText
release loRest
release loBdRequest
release loSbResponse
return
endif
lcResponseText = loSbResponse.GetAsString()
if (loSbResponse.LastMethodSuccess = .F.) then
? loSbResponse.LastErrorText
release loRest
release loBdRequest
release loSbResponse
return
endif
? lcResponseText
release loRest
release loBdRequest
release loSbResponse