From acb772f35705e7c43f72182d0d57b4a011eab2a2 Mon Sep 17 00:00:00 2001 From: raghav-rama Date: Sun, 25 Feb 2024 11:14:03 +0530 Subject: [PATCH] add: basic_auth.rs --- src/bin/basic_auth.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/basic_auth.rs diff --git a/src/bin/basic_auth.rs b/src/bin/basic_auth.rs new file mode 100644 index 0000000..1f955d0 --- /dev/null +++ b/src/bin/basic_auth.rs @@ -0,0 +1,19 @@ +use error_chain::error_chain; +use reqwest::blocking::Client; + +error_chain! { + foreign_links { + Io(std::io::Error); + HttpError(reqwest::Error); + } +} + +fn main() -> Result<()> { + let client = Client::new(); + let user = String::from("testuser"); + let passwd = Option::::None; + let url = format!("https://httpbin.org/get"); + let response = client.get(&url).basic_auth(user, passwd).send()?; + println!("{:?}", response); + Ok(()) +}