rust 循环延时请求api接口解析json 获取ip地址

180it 2023-03-03 PM 775℃ 0条
use std::collections::HashMap;
use std::thread::sleep;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let three_seconds = Duration::from_secs(3);
    loop {
        println!("1234");
//---------------------
        let resp = reqwest::get("https://httpbin.org/ip")
            .await?
            .json::<HashMap<String, String>>()
            .await?;
        println!("{:#?}", resp);
//---------------------
        sleep(three_seconds); // 延迟3秒
    }

    Ok(())
}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust 循环延时请求api接口解析json 获取ip地址