Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
Dim success As Boolean = False

Dim rest As New Chilkat.Rest
Dim bTls As Boolean = True
Dim bAutoReconnect As Boolean = True
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = False) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


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


Dim statusCode As Integer = rest.ReadResponseHeader()
If (statusCode < 0) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
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 Integer = rest.NumResponseHeaders
Dim i As Integer
For i = 0 To numHeaders - 1
    Dim value As String = rest.ResponseHdrValue(i)
    If (rest.LastMethodSuccess = False) Then
        Debug.WriteLine(rest.LastErrorText)
        Exit Sub
    End If

    Debug.WriteLine("Header " & i & " value: " & value)
Next