Help needed #2999
Unanswered
CheetoTrump
asked this question in
Q&A
Help needed
#2999
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Following the docs on hyper.rs i was looking at this and was confused on how to get the same responces as below nit outputting the body using println instead of stdout
use hyper::Client;
use hyper::body::HttpBody as _;
use tokio::io::{stdout, AsyncWriteExt as _};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// This is where we will setup our HTTP client requests.
// Previously...
let client = Client::new();
let uri = "http://httpbin.org/ip".parse()?;
let mut resp = client.get(uri).await?;
println!("Response: {}", resp.status());
// And now...
while let Some(chunk) = resp.body_mut().data().await {
stdout().write_all(&chunk?).await?;
}
}
Beta Was this translation helpful? Give feedback.
All reactions