Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL nStatusCode
LOCAL nNumHeaders
LOCAL i
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

//  Return the value of the response header at a zero-based index.  Use the same index with
//  ResponseHdrName to get the corresponding field name.
nNumHeaders := oRest:NumResponseHeaders

FOR i := 0 TO nNumHeaders - 1
    cValue := oRest:ResponseHdrValue(i)
    IF (oRest:LastMethodSuccess == 0)
        ? oRest:LastErrorText
        oRest:destroy()
        RETURN
    ENDIF

    ? "Header " + Str(i) + " value: " + cValue
NEXT

oRest:destroy()