Sample code for 30+ languages & platforms
PowerBuilder

Send a REST Request with a Streamed Body

See more REST Examples

Demonstrates Rest.FullRequestStream, which sends a complete request whose body is read from a Stream, then returns the response body as text.

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. Streaming the body is appropriate for large uploads because the data is read incrementally from the source (here a file) rather than being held entirely in memory.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_BodyStream
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.

//  The request body is read from a Stream.  Here the stream's source is a local file, which is
//  appropriate for large uploads because the data need not be held entirely in memory.
loo_BodyStream = create oleobject
li_rc = loo_BodyStream.ConnectToNewObject("Chilkat.Stream")

loo_BodyStream.SourceFile = "qa_data/upload.json"

loo_Rest.AddHeader("Content-Type","application/json")

//  The 3rd argument is the Stream that supplies the request body.
ls_ResponseText = loo_Rest.FullRequestStream("POST","/api/upload",loo_BodyStream)
if loo_Rest.LastMethodSuccess = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_BodyStream
    return
end if

Write-Debug ls_ResponseText


destroy loo_Rest
destroy loo_BodyStream