Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [package]
- name = "smol-test"
- version = "0.1.0"
- edition = "2021"
- [dependencies]
- anyhow = "1.0"
- futures = "0.3"
- reqwest = { version = "0.11", default-features = false, features = ["stream"] }
- tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
- */
- use futures::io::AsyncReadExt;
- use futures::TryStreamExt;
- use reqwest::{Client, Response};
- use std::io::{Error, ErrorKind};
- use std::time::Duration;
- #[tokio::main]
- async fn main() -> anyhow::Result<()> {
- let http_client = Client::builder()
- .connect_timeout(Duration::from_secs(5))
- .build()?;
- let r: Response = http_client.get("http://httpbin.org/get").send().await?;
- let mut reader = r
- .bytes_stream()
- .map_err(|e| Error::new(ErrorKind::Other, e))
- .into_async_read();
- let mut buf = Vec::new();
- let _ = reader.read_to_end(&mut buf).await?;
- println!("{:?}", buf);
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement