Skip to content

Instantly share code, notes, and snippets.

@wddwycc
Created December 2, 2017 03:54
Show Gist options
  • Save wddwycc/2aebdbfa077a9951bf83067a7d2ca4fc to your computer and use it in GitHub Desktop.
Save wddwycc/2aebdbfa077a9951bf83067a7d2ca4fc to your computer and use it in GitHub Desktop.
Send request use hyper.rs
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();
}
@wddwycc
Copy link
Author

wddwycc commented Dec 2, 2017

dependency

[dependencies]
futures = "0.1"
hyper = "0.11"
tokio-core = "0.1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment