Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 1, 2024
1 parent c96b729 commit 6dae563
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ntex/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ use ntex::http::client::{error::SendRequestError, Client};

#[ntex::main]
async fn main() -> Result<(), SendRequestError> {
std::env::set_var("RUST_LOG", "trace");
std::env::set_var("RUST_LOG", "ntex=trace");
env_logger::init();

let client = Client::new();

// Create request builder, configure request and send
loop {
let _response = client.get("https://www.google.com").send().await.unwrap();
ntex::time::sleep(std::time::Duration::from_secs(10)).await;
}
let mut response = client
.get("https://www.rust-lang.org/")
.header("User-Agent", "ntex")
.send()
.await?;

// server http response
println!("Response: {:?}", response);

// read response body
let body = response.body().await.unwrap();
println!("Downloaded: {:?} bytes", body.len());

Ok(())
}

0 comments on commit 6dae563

Please sign in to comment.