PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkRest.pb"
Procedure ChilkatExample()
success.i = 0
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
bTls.i = 1
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
success = CkRest::ckSendReqNoBody(rest,"GET","/api/items/123")
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
statusCode.i = CkRest::ckReadResponseHeader(rest)
If statusCode < 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; Return the value of a response header field by name. Header field names are case-insensitive.
contentType.s = CkRest::ckResponseHdrByName(rest,"Content-Type")
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
Debug "Content-Type: " + contentType
CkRest::ckDispose(rest)
ProcedureReturn
EndProcedure