Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
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

//  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 = .F.) then
        ? loRest.LastErrorText
        release loRest
        return
    endif

    ? "Header " + str(i) + " value: " + lcValue
next


release loRest