use tokio::{
io::{self, AsyncReadExt as _, AsyncWriteExt as _},
net::TcpStream,
};
#[tokio::main]
async fn main() -> io::Result<()> {
let mut stream = TcpStream::connect("baidu.com:80").await?;
const REQUEST: &[u8] = b"GET http://baidu.com/ HTTP/1.1\r\n\
Host: baidu.com\r\n\
\r\n";
stream.write_all(REQUEST).await?;
// Signal that we have done writing.
stream.shutdown().await?;
println!("Sent {} bytes", REQUEST.len());
let mut buf = vec![];
stream.read_to_end(&mut buf).await?;
println!("Received {} bytes", buf.len());
println!("{}", String::from_utf8_lossy(&buf));
Ok(())
}