Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL nStatusCode
LOCAL nNumHeaders
LOCAL i
LOCAL cName
LOCAL cValue
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
nSuccess := oRest:SendReqNoBody("GET", "/api/items/123")
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
nStatusCode := oRest:ReadResponseHeader()
IF (nStatusCode < 0)
? oRest:LastErrorText
oRest:destroy()
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.
nNumHeaders := oRest:NumResponseHeaders
FOR i := 0 TO nNumHeaders - 1
cName := oRest:ResponseHdrName(i)
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
cValue := oRest:ResponseHdrValue(i)
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
? cName + ": " + cValue
NEXT
oRest:destroy()