VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
set rest = CreateObject("Chilkat.Rest")
bTls = 1
bAutoReconnect = 1
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = 0) Then
outFile.WriteLine(rest.LastErrorText)
WScript.Quit
End If
success = rest.SendReqNoBody("GET","/api/items/123")
If (success = 0) Then
outFile.WriteLine(rest.LastErrorText)
WScript.Quit
End If
statusCode = rest.ReadResponseHeader()
If (statusCode < 0) Then
outFile.WriteLine(rest.LastErrorText)
WScript.Quit
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.
numHeaders = rest.NumResponseHeaders
For i = 0 To numHeaders - 1
value = rest.ResponseHdrValue(i)
If (rest.LastMethodSuccess = 0) Then
outFile.WriteLine(rest.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Header " & i & " value: " & value)
Next
outFile.Close