mirror of https://github.com/fafhrd91/actix-web
add new actix client
This commit is contained in:
parent
4f9a1ac3b7
commit
edfc817950
|
@ -1,25 +0,0 @@
|
|||
use actix_http::Error;
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> Result<(), Error> {
|
||||
std::env::set_var("RUST_LOG", "actix_http=trace");
|
||||
env_logger::init();
|
||||
|
||||
let client = awc::Client::new();
|
||||
|
||||
// Create request builder, configure request and send
|
||||
let mut response = client
|
||||
.get("https://www.rust-lang.org/")
|
||||
.header("User-Agent", "Actix-web")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
// server http response
|
||||
println!("Response: {:?}", response);
|
||||
|
||||
// read response body
|
||||
let body = response.body().await?;
|
||||
println!("Downloaded: {:?} bytes", body.len());
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "actix_web_client"
|
||||
version = "0.1.0"
|
||||
authors = ["Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "1.1"
|
||||
actix-web = { version = "2.0", features=["rustls"] }
|
|
@ -0,0 +1,18 @@
|
|||
use actix_web::client::Client;
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> Result<(), actix_web::Error> {
|
||||
// std::env::set_var("RUST_LOG", "actix_http=trace");
|
||||
let client = Client::default();
|
||||
|
||||
// Create request builder and send request
|
||||
let mut response = client
|
||||
.get("https://www.rust-lang.org") // <--- notice the "s" in "https://..."
|
||||
.header("User-Agent", "Actix-web")
|
||||
.send()
|
||||
.await?; // <- Send http request
|
||||
println!("Response: {:?}", response);
|
||||
let body = response.body().await?;
|
||||
println!("Downloaded: {:?} bytes", body.len());
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue