Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
loRest = createobject("CkRest")
llBTls = .T.
llBAutoReconnect = .T.
llSuccess = loRest.Connect("example.com",443,llBTls,llBAutoReconnect)
if (llSuccess = .F.) then
? loRest.LastErrorText
release loRest
return
endif
llSuccess = loRest.SendReqNoBody("GET","/api/items/123")
if (llSuccess = .F.) then
? loRest.LastErrorText
release loRest
return
endif
lnStatusCode = loRest.ReadResponseHeader()
if (lnStatusCode < 0) then
? loRest.LastErrorText
release loRest
return
endif
// Enumerate the response header fields by zero-based index. ResponseHdrName returns the field name
// and ResponseHdrValue returns the value at the same index.
lnNumHeaders = loRest.NumResponseHeaders
for i = 0 to lnNumHeaders - 1
lcName = loRest.ResponseHdrName(i)
if (loRest.LastMethodSuccess = .F.) then
? loRest.LastErrorText
release loRest
return
endif
lcValue = loRest.ResponseHdrValue(i)
if (loRest.LastMethodSuccess = .F.) then
? loRest.LastErrorText
release loRest
return
endif
? lcName + ": " + lcValue
next
release loRest