DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Boolean iBAutoReconnect
Integer iStatusCode
Integer iNumHeaders
Integer i
String sValue
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 the response header at a zero-based index. Use the same index with
// ResponseHdrName to get the corresponding field name.
Get ComNumResponseHeaders Of hoRest To iNumHeaders
For i From 0 To (iNumHeaders - 1)
Get ComResponseHdrValue Of hoRest i To sValue
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Header " i " value: " sValue
Loop
End_Procedure