Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
set rest [new_CkRest]
set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
set success [CkRest_SendReqNoBody $rest "GET" "/api/items/123"]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
set statusCode [CkRest_ReadResponseHeader $rest]
if {$statusCode < 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
# Return the value of the response header at a zero-based index. Use the same index with
# ResponseHdrName to get the corresponding field name.
set numHeaders [CkRest_get_NumResponseHeaders $rest]
for {set i 0} {$i <= [expr $numHeaders - 1]} {incr i} {
set value [CkRest_responseHdrValue $rest $i]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
puts "Header $i value: $value"
}
delete_CkRest $rest