Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL lnStatusCode
LOCAL lnNumHeaders
LOCAL i
LOCAL lcName
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

*  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 = 0) THEN
        ? loRest.LastErrorText
        RELEASE loRest
        CANCEL
    ENDIF

    lcValue = loRest.ResponseHdrValue(i)
    IF (loRest.LastMethodSuccess = 0) THEN
        ? loRest.LastErrorText
        RELEASE loRest
        CANCEL
    ENDIF

    ? lcName + ": " + lcValue
NEXT

RELEASE loRest