Created
December 2, 2017 03:54
-
-
Save wddwycc/2aebdbfa077a9951bf83067a7d2ca4fc to your computer and use it in GitHub Desktop.
Send request use hyper.rs
This file contains hidden or 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
extern crate hyper; | |
extern crate futures; | |
extern crate tokio_core; | |
use std::io::{self, Write}; | |
use futures::{Future, Stream}; | |
use hyper::Client; | |
use tokio_core::reactor::Core; | |
fn main() { | |
let mut core = Core::new().unwrap(); | |
let client = Client::new(&core.handle()); | |
let uri = "http://httpbin.org/ip".parse().unwrap(); | |
let work = client.get(uri).and_then(|res| { | |
println!("Response: {}", res.status()); | |
res.body().for_each(|chunk| { | |
io::stdout() | |
.write_all(&chunk) | |
.map_err(From::from) | |
}) | |
}); | |
core.run(work).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependency