Sample code for 30+ languages & platforms
PowerBuilder

Read the REST Response Body into a StringBuilder

See more REST Examples

Demonstrates Rest.ReadRespSb, which reads the response body as text into a StringBuilder, replacing its previous contents.

Background. The staged request model separates sending from reading: a SendReq method transmits the request, ReadResponseHeader reads the status line and headers, and a ReadResp method reads the body. This gives fine control over large or streamed messages compared with the single-call full-request methods.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
integer li_StatusCode
oleobject loo_SbResponse
string ls_ResponseBody

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

li_Success = loo_Rest.SendReqNoBody("GET","/api/items/123")
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

li_StatusCode = loo_Rest.ReadResponseHeader()
if li_StatusCode < 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

//  Read the response body as text into a StringBuilder, replacing its previous contents.
loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.ReadRespSb(loo_SbResponse)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponse
    return
end if

ls_ResponseBody = loo_SbResponse.GetAsString()
if loo_SbResponse.LastMethodSuccess = 0 then
    Write-Debug loo_SbResponse.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponse
    return
end if

Write-Debug ls_ResponseBody


destroy loo_Rest
destroy loo_SbResponse