Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created May 2, 2015 21:00
Show Gist options
  • Save ucarion/1a8b23d89b879e8d4781 to your computer and use it in GitHub Desktop.
Save ucarion/1a8b23d89b879e8d4781 to your computer and use it in GitHub Desktop.
use std::io::{self, Read, Write};
use std::net::Shutdown;
use hyper::net::{HttpConnector, NetworkConnector, HttpStream};
fn fetch_http(host: &str, port: u16, scheme: &str, data: &[u8]) -> io::Result<Vec<u8>> {
let mut connector = HttpConnector(None);
let mut stream = connector.connect(host, port, scheme).unwrap();
println!("{:?}", stream);
stream.write(data).unwrap();
let mut buf = Vec::new();
stream.read_to_end(&mut buf).unwrap();
Ok(buf)
}
fn main() {
let msg = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n";
println!("{:?}", fetch_http("example.com", 80, "http", msg));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment