Sample code for 30+ languages & platforms
PowerBuilder

Send a REST Request using StringBuilder Bodies

See more REST Examples

Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.

Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.

Chilkat PowerBuilder Downloads

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

//  FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
//  response body in a second StringBuilder.  This avoids extra string conversions for large bodies.
loo_SbRequest = create oleobject
li_rc = loo_SbRequest.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbRequest.Append("{ ~"query~": ~"chilkat~" }")

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

loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/api/search",loo_SbRequest,loo_SbResponse)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbRequest
    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_SbRequest
    destroy loo_SbResponse
    return
end if

Write-Debug ls_ResponseText


destroy loo_Rest
destroy loo_SbRequest
destroy loo_SbResponse