Chilkat2-Python
Chilkat2-Python
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 Chilkat2-Python Downloads
import sys
import chilkat2
success = False
rest = chilkat2.Rest()
bTls = True
bAutoReconnect = True
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
if (success == False):
print(rest.LastErrorText)
sys.exit()
success = rest.SendReqNoBody("GET","/api/items/123")
if (success == False):
print(rest.LastErrorText)
sys.exit()
statusCode = rest.ReadResponseHeader()
if (statusCode < 0):
print(rest.LastErrorText)
sys.exit()
# Enumerate the response header fields by zero-based index. ResponseHdrName returns the field name
# and ResponseHdrValue returns the value at the same index.
numHeaders = rest.NumResponseHeaders
for i in range(0,numHeaders):
name = rest.ResponseHdrName(i)
if (rest.LastMethodSuccess == False):
print(rest.LastErrorText)
sys.exit()
value = rest.ResponseHdrValue(i)
if (rest.LastMethodSuccess == False):
print(rest.LastErrorText)
sys.exit()
print(name + ": " + value)