Sample code for 30+ languages & platforms
PowerShell

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 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 a response header field by name.  Header field names are case-insensitive.
$contentType = $rest.ResponseHdrByName("Content-Type")
if ($rest.LastMethodSuccess -eq $false) {
    $($rest.LastErrorText)
    exit
}

$("Content-Type: " + $contentType)