client.rs 635 B

1234567891011121314151617181920
  1. use hyper::{body::HttpBody as _, Client};
  2. use hyper_tls::HttpsConnector;
  3. use tokio::io::{self, AsyncWriteExt as _};
  4. #[tokio::main(flavor = "current_thread")]
  5. async fn main() -> Result<(), Box<dyn std::error::Error>> {
  6. let https = HttpsConnector::new();
  7. let client = Client::builder().build::<_, hyper::Body>(https);
  8. let mut res = client.get("https://hyper.rs".parse()?).await?;
  9. println!("Status: {}", res.status());
  10. println!("Headers:\n{:#?}", res.headers());
  11. while let Some(chunk) = res.body_mut().data().await {
  12. let chunk = chunk?;
  13. io::stdout().write_all(&chunk).await?
  14. }
  15. Ok(())
  16. }