client.rs 731 B

123456789101112131415161718192021222324
  1. use security_framework::secure_transport::ClientBuilder;
  2. use std::io::{Read, Write};
  3. use std::net::TcpStream;
  4. fn main() {
  5. let stream = TcpStream::connect("google.com:443").unwrap();
  6. let mut stream = ClientBuilder::new()
  7. .handshake("google.com", stream)
  8. .unwrap();
  9. println!(
  10. "negotiated chipher: {:?}",
  11. stream.context().negotiated_cipher().unwrap()
  12. );
  13. println!(
  14. "negotiated version: {:?}",
  15. stream.context().negotiated_protocol_version().unwrap()
  16. );
  17. stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
  18. stream.flush().unwrap();
  19. let mut buf = vec![];
  20. stream.read_to_end(&mut buf).unwrap();
  21. println!("{}", String::from_utf8_lossy(&buf));
  22. }