Sample code for 30+ languages & platforms
Visual Basic 6.0

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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

Dim rest As New ChilkatRest
Dim bTls As Long
bTls = 1
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = 0) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

success = rest.SendReqNoBody("GET","/api/items/123")
If (success = 0) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

Dim statusCode As Long
statusCode = rest.ReadResponseHeader()
If (statusCode < 0) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

'  Enumerate the response header fields by zero-based index.  ResponseHdrName returns the field name
'  and ResponseHdrValue returns the value at the same index.
Dim numHeaders As Long
numHeaders = rest.NumResponseHeaders
Dim i As Long
For i = 0 To numHeaders - 1
    Dim name As String
    name = rest.ResponseHdrName(i)
    If (rest.LastMethodSuccess = 0) Then
        Debug.Print rest.LastErrorText
        Exit Sub
    End If

    Dim value As String
    value = rest.ResponseHdrValue(i)
    If (rest.LastMethodSuccess = 0) Then
        Debug.Print rest.LastErrorText
        Exit Sub
    End If

    Debug.Print name & ": " & value
Next