Skip to content

Instantly share code, notes, and snippets.

@povilasb
Created May 7, 2017 09:58
Show Gist options
  • Save povilasb/849ed3a6145dcfbb33311fcdcf86e6f2 to your computer and use it in GitHub Desktop.
Save povilasb/849ed3a6145dcfbb33311fcdcf86e6f2 to your computer and use it in GitHub Desktop.
Do HTTP request with raw sockets
use std::net::TcpStream;
use std::io::{Write, Read};
fn main() {
let target_addr = "54.243.92.110:80"; // httpbin.org
let mut stream = TcpStream::connect(target_addr).unwrap();
stream.write(b"GET /ip HTTP/1.1\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n");
let mut buff = [0; 65536];
stream.read(&mut buff);
println!("{}", std::str::from_utf8(&buff).unwrap())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment