1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00
actix-web/awc/examples/client.rs

28 lines
717 B
Rust
Raw Normal View History

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