PowerBuilder
PowerBuilder
Enumerate REST Response Header Names
See more REST Examples
Demonstrates Rest.ResponseHdrName, which returns the field name of the response header at a zero-based index. The example enumerates all headers, pairing each name with its value.
Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one. ResponseHdrName and ResponseHdrValue use the same index for a given header.
Chilkat PowerBuilder Downloads
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_Name
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
// Enumerate the response header fields by zero-based index. ResponseHdrName returns the field name
// and ResponseHdrValue returns the value at the same index.
li_NumHeaders = loo_Rest.NumResponseHeaders
for i = 0 to li_NumHeaders - 1
ls_Name = loo_Rest.ResponseHdrName(i)
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
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 ls_Name + ": " + ls_Value
next
destroy loo_Rest