Sample code for 30+ languages & platforms
Rust

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Rust Downloads

Rust
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// To use HTTP Basic authentication:
http.set_login("myLogin");
http.set_password("myPassword");
http.set_basic_auth(true);

// Run the test using this URL with the credentials above.  
// (Works while httpbin.org keeps the test endpoint available.)
let Ok(json_response) = http.quick_get_str("https://httpbin.org/basic-auth/myLogin/myPassword") else {
    println!("{}", http.last_error_text());
    return;
};

println!("Response status code: {}", http.last_status());

println!("{}", json_response);

// Output:

// Response status code: 200
// {
//   "authenticated": true, 
//   "user": "myLogin"
// }