1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-19 06:04:40 +01:00
actix-web/awc/examples/client.rs

26 lines
643 B
Rust
Raw Normal View History

2021-06-17 17:57:58 +01:00
use std::error::Error as StdError;
2019-01-28 20:41:09 -08:00
2020-06-18 15:45:30 +01:00
#[actix_web::main]
2021-06-17 17:57:58 +01:00
async fn main() -> Result<(), Box<dyn StdError>> {
2019-01-28 20:41:09 -08:00
std::env::set_var("RUST_LOG", "actix_http=trace");
env_logger::init();
2019-11-26 17:16:33 +06:00
let client = awc::Client::new();
2019-11-20 23:33:22 +06:00
2019-11-26 17:16:33 +06:00
// Create request builder, configure request and send
let mut response = client
.get("https://www.rust-lang.org/")
2021-01-15 02:11:10 +00:00
.append_header(("User-Agent", "Actix-web"))
2019-11-26 17:16:33 +06:00
.send()
.await?;
2019-11-20 23:33:22 +06:00
2019-11-26 17:16:33 +06:00
// server http response
println!("Response: {:?}", response);
2019-11-20 23:33:22 +06:00
2019-11-26 17:16:33 +06:00
// read response body
let body = response.body().await?;
println!("Downloaded: {:?} bytes", body.len());
2019-01-28 20:41:09 -08:00
2019-11-26 17:16:33 +06:00
Ok(())
2019-01-28 20:41:09 -08:00
}