Tcl
Tcl
Add a Query Parameter from a StringBuilder
See more REST Examples
Demonstrates Rest.AddQueryParamSb, which adds or replaces a query parameter whose value is read from a StringBuilder. The 1st argument is the name and the 2nd is the StringBuilder.
Background. This variant is convenient when the parameter value has already been assembled in a StringBuilder, avoiding an extra conversion to a plain string.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set rest [new_CkRest]
# Connect to the REST server. The 3rd argument enables TLS (use 1 for HTTPS on port 443),
# and the 4th enables automatic reconnection if the connection is dropped between requests.
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
}
# The parameter value can also be supplied from a StringBuilder. The 1st argument is the name and
# the 2nd is the StringBuilder holding the value.
set sbValue [new_CkStringBuilder]
CkStringBuilder_Append $sbValue "chilkat rest"
CkRest_AddQueryParamSb $rest "q" $sbValue
set responseText [CkRest_fullRequestNoBody $rest "GET" "/api/search"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkStringBuilder $sbValue
exit
}
puts "$responseText"
delete_CkRest $rest
delete_CkStringBuilder $sbValue