まずはGetリクエストから
use async_std::task; fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { task::block_on(async { let mut res = surf::get("https://httpbin.org/get").await?; dbg!(res.body_string().await?); Ok(()) }) }
#[async_std::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { let mut res = surf::get("https://httpbin.org/get").await?; dbg!(res.body_string().await?); Ok(()) }
[src/main.rs:4:5] res.body_string().await? = “{\n \”args\”: {}, \n \”headers\”: {\n \”Accept\”: \”*/*\”, \n \”Accept-Encoding\”: \”deflate, gzip\”, \n \”Host\”: \”httpbin.org\”, \n \”User-Agent\”: \”curl/8.11.0-DEV isahc/0.7.6\”, \n \”X-Amzn-Trace-Id\”: \”Root=1-676a57b7-3de7e4ff65be3baf597f36f8\”\n }, \n \”origin\”: \”106.155.3.182\”, \n \”url\”: \”https://httpbin.org/get\”\n}\n”