Last active
August 29, 2015 14:21
-
-
Save benaryorg/7df08675371a47a38502 to your computer and use it in GitHub Desktop.
get text from an HTTP server in rust
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::net::*; | |
use std::io::prelude::*; | |
fn main() | |
{ | |
let mut buf:String; | |
let ip="google.com"; | |
let port=80; | |
let mut stream=TcpStream::connect((ip,port)).unwrap(); | |
let _=stream.write(b"GET / HTTP/1.0\nHost: {}\n\n",ip); | |
while | |
{ | |
buf=String::new(); | |
let res=stream.read_to_string(&mut buf).unwrap(); | |
print!("{}",buf); | |
res>0 | |
}{} | |
println!(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment