(Swift) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// To use HTTP Basic authentication:
http.login = "myLogin"
http.password = "myPassword"
http.basicAuth = true
// Run the test using this URL with the credentials above.
// (Works while httpbin.org keeps the test endpoint available.)
var jsonResponse: String? = http.quickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("Response status code: \(http.lastStatus.intValue)")
print("\(jsonResponse!)")
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }
}
|