Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL lnStatusCode
LOCAL lnNumHeaders
LOCAL i
LOCAL lcValue
lnSuccess = 0
loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
lnSuccess = loRest.SendReqNoBody("GET","/api/items/123")
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
lnStatusCode = loRest.ReadResponseHeader()
IF (lnStatusCode < 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
* Return the value of the response header at a zero-based index. Use the same index with
* ResponseHdrName to get the corresponding field name.
lnNumHeaders = loRest.NumResponseHeaders
FOR i = 0 TO lnNumHeaders - 1
lcValue = loRest.ResponseHdrValue(i)
IF (loRest.LastMethodSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
? "Header " + STR(i) + " value: " + lcValue
NEXT
RELEASE loRest