Bring back surf example
parent
5dd0ab00a0
commit
62be014edc
@ -1,15 +0,0 @@
|
||||
//! Fetches the HTML contents of the Rust website.
|
||||
|
||||
#![feature(async_await)]
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
use async_std::task;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
task::block_on(async {
|
||||
// let contents = surf::get("https://www.rust-lang.org").recv_string().await?;
|
||||
// println!("{}", contents);
|
||||
Ok(())
|
||||
})
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
//! Creates a web request to the Rust website.
|
||||
|
||||
#![feature(async_await)]
|
||||
|
||||
use async_std::task;
|
||||
|
||||
fn main() -> Result<(), surf::Exception> {
|
||||
task::block_on(async {
|
||||
let url = "https://www.rust-lang.org";
|
||||
let mut response = surf::get(url).await?;
|
||||
let body = response.body_string().await?;
|
||||
|
||||
dbg!(url);
|
||||
dbg!(response.status());
|
||||
dbg!(response.version());
|
||||
dbg!(response.headers());
|
||||
dbg!(body.len());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue