PowerBuilder
PowerBuilder
Get a REST Response Header by Name
See more REST Examples
Demonstrates Rest.ResponseHdrByName, which returns the value of a response header field by name. Header field names are case-insensitive.
Background. Response headers are available after ReadResponseHeader has read the status line and headers. Lookup by name is convenient when a specific header, such as Content-Type, is needed.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
integer li_StatusCode
string ls_ContentType
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 a response header field by name. Header field names are case-insensitive.
ls_ContentType = loo_Rest.ResponseHdrByName("Content-Type")
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
Write-Debug "Content-Type: " + ls_ContentType
destroy loo_Rest