PureBasic
PureBasic
Enumerate REST Response Header Names
See more REST Examples
Demonstrates Rest.ResponseHdrName, which returns the field name of the response header at a zero-based index. The example enumerates all headers, pairing each name with its value.
Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one. ResponseHdrName and ResponseHdrValue use the same index for a given header.
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
; Enumerate the response header fields by zero-based index. ResponseHdrName returns the field name
; and ResponseHdrValue returns the value at the same index.
numHeaders.i = CkRest::ckNumResponseHeaders(rest)
i.i
For i = 0 To numHeaders - 1
name.s = CkRest::ckResponseHdrName(rest,i)
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
value.s = CkRest::ckResponseHdrValue(rest,i)
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
Debug name + ": " + value
Next
CkRest::ckDispose(rest)
ProcedureReturn
EndProcedure