Sample code for 30+ languages & platforms
B4X

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


'  Return the value of the response header at a zero-based index.  Use the same index with
'  ResponseHdrName to get the corresponding field name.
Dim numHeaders As Int = rest.NumResponseHeaders
Dim i As Int
For i = 0 To numHeaders - 1
    Dim value As String = rest.ResponseHdrValue(i)
    If rest.LastMethodSuccess = False Then
        Log(rest.LastErrorText)
        Return
    End If

    Log("Header " & i & " value: " & value)
Next