(Tcl) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# To use HTTP Basic authentication:
CkHttp_put_Login $http "myLogin"
CkHttp_put_Password $http "myPassword"
CkHttp_put_BasicAuth $http 1
# Run the test using this URL with the credentials above.
# (Works while httpbin.org keeps the test endpoint available.)
set jsonResponse [CkHttp_quickGetStr $http "https://httpbin.org/basic-auth/myLogin/myPassword"]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
exit
}
puts "Response status code: [CkHttp_get_LastStatus $http]"
puts "$jsonResponse"
# Output:
# Response status code: 200
# {
# "authenticated": true,
# "user": "myLogin"
# }
delete_CkHttp $http
|