(Go) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := Http_Ref.html">chilkat.NewHttp()
// To use HTTP Basic authentication:
http.SetLogin("myLogin")
http.SetPassword("myPassword")
http.SetBasicAuth(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.LastMethodSuccess() == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
return
}
fmt.Println("Response status code: ", http.LastStatus())
fmt.Println(*jsonResponse)
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }
http.DisposeHttp()
|