Created
May 2, 2015 21:00
-
-
Save ucarion/1a8b23d89b879e8d4781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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