Sample code for 30+ languages & platforms
PowerShell

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 PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$rest = New-Object Chilkat.Rest
$bTls = $true
$bAutoReconnect = $true
$success = $rest.Connect("example.com",443,$bTls,$bAutoReconnect)
if ($success -eq $false) {
    $($rest.LastErrorText)
    exit
}

$success = $rest.SendReqNoBody("GET","/api/items/123")
if ($success -eq $false) {
    $($rest.LastErrorText)
    exit
}

$statusCode = $rest.ReadResponseHeader()
if ($statusCode -lt 0) {
    $($rest.LastErrorText)
    exit
}

#  Enumerate the response header fields by zero-based index.  ResponseHdrName returns the field name
#  and ResponseHdrValue returns the value at the same index.
$numHeaders = $rest.NumResponseHeaders

for ($i = 0; $i -le $numHeaders - 1; $i++) {
    $name = $rest.ResponseHdrName($i)
    if ($rest.LastMethodSuccess -eq $false) {
        $($rest.LastErrorText)
        exit
    }

    $value = $rest.ResponseHdrValue($i)
    if ($rest.LastMethodSuccess -eq $false) {
        $($rest.LastErrorText)
        exit
    }

    $($name + ": " + $value)
}