(Tcl) Example: Http.SetUrlVar method
Demonstrates the HTTP SetUrlVar method.
load ./chilkat.dll
set success 0
set http [new_CkHttp]
set url "https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}"
# When the request is sent, the {$symbol} is replaced with "MSFT"
# and the {$api_key} is replaced with "1234567890ABCDEF"
CkHttp_SetUrlVar $http "symbol" "MSFT"
CkHttp_SetUrlVar $http "api_key" "1234567890ABCDEF"
set sbJson [new_CkStringBuilder]
set success [CkHttp_QuickGetSb $http $url $sbJson]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkStringBuilder $sbJson
exit
}
set statusCode [CkHttp_get_LastStatus $http]
if {$statusCode != 200} then {
puts "Status code: $statusCode"
puts "Error Message:"
puts [CkStringBuilder_getAsString $sbJson]
} else {
puts "JSON Stock Quote:"
puts [CkStringBuilder_getAsString $sbJson]
}
# Output:
# JSON Stock Quote:
# {"c":522.98,"d":0.5,"dp":0.0957,"h":524.51,"l":520.86,"o":524.28,"pc":522.48,"t":1755271948}
delete_CkHttp $http
delete_CkStringBuilder $sbJson
|