PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_BdRequest
integer li_BLoaded
oleobject loo_SbResponse
string ls_ResponseText
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
// 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.
loo_BdRequest = create oleobject
li_rc = loo_BdRequest.ConnectToNewObject("Chilkat.BinData")
li_BLoaded = loo_BdRequest.LoadFile("qa_data/image.png")
if li_BLoaded <> 1 then
Write-Debug "Failed to load the request body file."
destroy loo_Rest
destroy loo_BdRequest
return
end if
loo_Rest.AddHeader("Content-Type","image/png")
loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.FullRequestBd("PUT","/api/images/1",loo_BdRequest,loo_SbResponse)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_BdRequest
destroy loo_SbResponse
return
end if
ls_ResponseText = loo_SbResponse.GetAsString()
if loo_SbResponse.LastMethodSuccess = 0 then
Write-Debug loo_SbResponse.LastErrorText
destroy loo_Rest
destroy loo_BdRequest
destroy loo_SbResponse
return
end if
Write-Debug ls_ResponseText
destroy loo_Rest
destroy loo_BdRequest
destroy loo_SbResponse