Sample code for 30+ languages & platforms
Xbase++

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

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL nStatusCode
LOCAL cContentType

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 a response header field by name.  Header field names are case-insensitive.
cContentType := oRest:ResponseHdrByName("Content-Type")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

? "Content-Type: " + cContentType

oRest:destroy()