Sample code for 30+ languages & platforms
AutoIt

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

;  Enumerate the response header fields by zero-based index.  ResponseHdrName returns the field name
;  and ResponseHdrValue returns the value at the same index.
Local $iNumHeaders = $oRest.NumResponseHeaders
Local $i
For $i = 0 To $iNumHeaders - 1
Local $sName = $oRest.ResponseHdrName($i)
    If ($oRest.LastMethodSuccess = False) Then
        ConsoleWrite($oRest.LastErrorText & @CRLF)
        Exit
    EndIf

Local $sValue = $oRest.ResponseHdrValue($i)
    If ($oRest.LastMethodSuccess = False) Then
        ConsoleWrite($oRest.LastErrorText & @CRLF)
        Exit
    EndIf

    ConsoleWrite($sName & ": " & $sValue & @CRLF)
Next