Sample code for 30+ languages & platforms
Lianja

Get a REST Response Header by Name

See more REST Examples

Demonstrates Rest.ResponseHdrByName, which returns the value of a response header field by name. Header field names are case-insensitive.

Background. Response headers are available after ReadResponseHeader has read the status line and headers. Lookup by name is convenient when a specific header, such as Content-Type, is needed.

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 a response header field by name.  Header field names are case-insensitive.
lcContentType = loRest.ResponseHdrByName("Content-Type")
if (loRest.LastMethodSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    return
endif

? "Content-Type: " + lcContentType


release loRest