Sample code for 30+ languages & platforms
PowerBuilder

Get a REST Response Header Value by Index

See more REST Examples

Demonstrates Rest.ResponseHdrValue, which returns the value of the response header at a zero-based index. The same index used with ResponseHdrName gives the corresponding field name.

Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one, after ReadResponseHeader has been called.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
integer li_StatusCode
integer li_NumHeaders
integer i
string ls_Value

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

//  Return the value of the response header at a zero-based index.  Use the same index with
//  ResponseHdrName to get the corresponding field name.
li_NumHeaders = loo_Rest.NumResponseHeaders

for i = 0 to li_NumHeaders - 1
    ls_Value = loo_Rest.ResponseHdrValue(i)
    if loo_Rest.LastMethodSuccess = 0 then
        Write-Debug loo_Rest.LastErrorText
        destroy loo_Rest
        return
    end if

    Write-Debug "Header " + string(i) + " value: " + ls_Value
next


destroy loo_Rest