(Ruby) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
require 'chilkat'
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = Chilkat::CkHttp.new()
# To use HTTP Basic authentication:
http.put_Login("myLogin")
http.put_Password("myPassword")
http.put_BasicAuth(true)
# Run the test using this URL with the credentials above.
# (Works while httpbin.org keeps the test endpoint available.)
jsonResponse = http.quickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
if (http.get_LastMethodSuccess() == false)
print http.lastErrorText() + "\n";
exit
end
print "Response status code: " + http.get_LastStatus().to_s() + "\n";
print jsonResponse + "\n";
# Output:
# Response status code: 200
# {
# "authenticated": true,
# "user": "myLogin"
# }
|