Sample code for 30+ languages & platforms
PowerShell

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 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
}

#  Return the value of the response header at a zero-based index.  Use the same index with
#  ResponseHdrName to get the corresponding field name.
$numHeaders = $rest.NumResponseHeaders

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

    $("Header " + $i + " value: " + $value)
}