use std::{
    io::{self, Read as _, Write as _},
    net::{Shutdown, TcpStream},
};

fn main() -> io::Result<()> {
    let mut stream = TcpStream::connect("baidu.com:80")?;

    const REQUEST: &[u8] = b"GET http://baidu.com/ HTTP/1.1\r\n\
        Host: baidu.com\r\n\
        \r\n";

    stream.write_all(REQUEST)?;

    // Signal that we have done writing.
    stream.shutdown(Shutdown::Write)?;
    println!("Sent {} bytes", REQUEST.len());

    let mut buf = vec![];
    stream.read_to_end(&mut buf)?;
    println!("Received {} bytes", buf.len());

    println!("{}", String::from_utf8_lossy(&buf));
    Ok(())
}