DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Boolean iBAutoReconnect
Integer iStatusCode
String sContentType
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Move True To iBTls
Move True To iBAutoReconnect
Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSendReqNoBody Of hoRest "GET" "/api/items/123" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComReadResponseHeader Of hoRest To iStatusCode
If (iStatusCode < 0) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Return the value of a response header field by name. Header field names are case-insensitive.
Get ComResponseHdrByName Of hoRest "Content-Type" To sContentType
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Content-Type: " sContentType
End_Procedure