use hyper::{body::HttpBody, Client};
use hyper::client::HttpConnector;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client: Client<HttpConnector> = Client::new();
let uri = "http://httpbin.org/get".parse()?;
println!("通过代理发送请求到: {}", uri);
let mut res = client.get(uri).await?;
println!("响应状态: {}", res.status());
println!("响应头:");
for (name, value) in res.headers() {
println!(" {}: {}", name, value.to_str().unwrap_or("[binary]"));
}
let mut body = String::new();
while let Some(chunk) = res.body_mut().data().await {
let chunk = chunk?;
body.push_str(&String::from_utf8_lossy(&chunk));
}
println!("响应体长度: {} 字节", body.len());
println!("响应体内容:");
println!("{}", body);
Ok(())
}