2023-01-01 20:56:27 +00:00
|
|
|
#![allow(clippy::uninlined_format_args)]
|
|
|
|
|
2021-06-17 16:57:58 +00:00
|
|
|
use std::error::Error as StdError;
|
2019-01-29 04:41:09 +00:00
|
|
|
|
2022-01-19 21:36:14 +00:00
|
|
|
#[tokio::main]
|
2021-06-17 16:57:58 +00:00
|
|
|
async fn main() -> Result<(), Box<dyn StdError>> {
|
2022-01-19 21:36:14 +00:00
|
|
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
2019-01-29 04:41:09 +00:00
|
|
|
|
2022-01-19 21:36:14 +00:00
|
|
|
// construct request builder
|
2019-11-26 11:16:33 +00:00
|
|
|
let client = awc::Client::new();
|
2019-11-20 17:33:22 +00:00
|
|
|
|
2022-01-19 21:36:14 +00:00
|
|
|
// configure request
|
2021-06-19 19:23:06 +00:00
|
|
|
let request = client
|
2019-11-26 11:16:33 +00:00
|
|
|
.get("https://www.rust-lang.org/")
|
2021-06-19 19:23:06 +00:00
|
|
|
.append_header(("User-Agent", "Actix-web"));
|
|
|
|
|
|
|
|
println!("Request: {:?}", request);
|
|
|
|
|
|
|
|
let mut response = request.send().await?;
|
2019-11-20 17:33:22 +00:00
|
|
|
|
2022-01-19 21:36:14 +00:00
|
|
|
// server response head
|
2019-11-26 11:16:33 +00:00
|
|
|
println!("Response: {:?}", response);
|
2019-11-20 17:33:22 +00:00
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
// read response body
|
|
|
|
let body = response.body().await?;
|
|
|
|
println!("Downloaded: {:?} bytes", body.len());
|
2019-01-29 04:41:09 +00:00
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
Ok(())
|
2019-01-29 04:41:09 +00:00
|
|
|
}
|