Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Last active August 29, 2015 14:21
Show Gist options
  • Save benaryorg/7df08675371a47a38502 to your computer and use it in GitHub Desktop.
Save benaryorg/7df08675371a47a38502 to your computer and use it in GitHub Desktop.
get text from an HTTP server in rust
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