2019-03-26 19:31:51 +00:00
|
|
|
use actix_http::Error;
|
2019-01-29 04:41:09 +00:00
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> Result<(), Error> {
|
2019-01-29 04:41:09 +00:00
|
|
|
std::env::set_var("RUST_LOG", "actix_http=trace");
|
|
|
|
env_logger::init();
|
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
let client = awc::Client::new();
|
2019-11-20 17:33:22 +00:00
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
// Create request builder, configure request and send
|
|
|
|
let mut response = client
|
|
|
|
.get("https://www.rust-lang.org/")
|
|
|
|
.header("User-Agent", "Actix-web")
|
|
|
|
.send()
|
|
|
|
.await?;
|
2019-11-20 17:33:22 +00:00
|
|
|
|
2019-11-26 11:16:33 +00:00
|
|
|
// server http response
|
|
|
|
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
|
|
|
}
|