1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-08-02 02:35:04 +00:00
actix-web/examples/client.rs

28 lines
707 B
Rust
Raw Normal View History

2019-03-26 19:31:51 +00:00
use actix_http::Error;
2019-01-29 04:41:09 +00:00
use actix_rt::System;
fn main() -> Result<(), Error> {
std::env::set_var("RUST_LOG", "actix_http=trace");
env_logger::init();
2019-11-20 17:33:22 +00:00
System::new("test").block_on(async {
let client = awc::Client::new();
// Create request builder, configure request and send
let mut response = client
.get("https://www.rust-lang.org/")
2019-01-29 04:41:09 +00:00
.header("User-Agent", "Actix-web")
2019-11-20 17:33:22 +00:00
.send()
.await?;
// server http response
println!("Response: {:?}", response);
// read response body
let body = response.body().await?;
println!("Downloaded: {:?} bytes", body.len());
2019-01-29 04:41:09 +00:00
2019-11-20 17:33:22 +00:00
Ok(())
})
2019-01-29 04:41:09 +00:00
}