Sample code for 30+ languages & platforms
B4X

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

B4X
Dim success As Boolean = False

Dim rest As ChilkatRest
rest.Initialize("rest")
Dim bTls As Boolean = True
Dim bAutoReconnect As Boolean = True
success = rest.Connect("example.com", 443, bTls, bAutoReconnect)
If success = False Then
    Log(rest.LastErrorText)
    Return
End If


success = rest.SendReqNoBody("GET", "/api/items/123")
If success = False Then
    Log(rest.LastErrorText)
    Return
End If


Dim statusCode As Int = rest.ReadResponseHeader
If statusCode < 0 Then
    Log(rest.LastErrorText)
    Return
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 Int = rest.NumResponseHeaders
Dim i As Int
For i = 0 To numHeaders - 1
    Dim name As String = rest.ResponseHdrName(i)
    If rest.LastMethodSuccess = False Then
        Log(rest.LastErrorText)
        Return
    End If

    Dim value As String = rest.ResponseHdrValue(i)
    If rest.LastMethodSuccess = False Then
        Log(rest.LastErrorText)
        Return
    End If

    Log(name & ": " & value)
Next