Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

$oRest = ObjCreate("Chilkat.Rest")
Local $bTls = True
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("example.com",443,$bTls,$bAutoReconnect)
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.SendReqNoBody("GET","/api/items/123")
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $iStatusCode = $oRest.ReadResponseHeader()
If ($iStatusCode < 0) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

;  Return the value of the response header at a zero-based index.  Use the same index with
;  ResponseHdrName to get the corresponding field name.
Local $iNumHeaders = $oRest.NumResponseHeaders
Local $i
For $i = 0 To $iNumHeaders - 1
Local $sValue = $oRest.ResponseHdrValue($i)
    If ($oRest.LastMethodSuccess = False) Then
        ConsoleWrite($oRest.LastErrorText & @CRLF)
        Exit
    EndIf

    ConsoleWrite("Header " & $i & " value: " & $sValue & @CRLF)
Next