rust 请求包reqwest实例

共 923字,需浏览 2分钟

 ·

2023-12-06 23:00

cargo.toml

reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }


main.rs

use serde_json::{Value};
use reqwest;
use std::error::Error;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = reqwest::Client::new();
    let doge = client
        .get("https://datacenter.eastmoney.com/securities/api/data/v1/get?client=APP&filter=%28BOARD_CODE_BK%3D%22BK0815%22%29&reportName=RPT_CUSTOM_BOARD_TAG&source=SECURITIES")
        .header("Accept", "text/plain")
        .timeout(Duration::from_secs(3))
        .send()
        .await?
        .text()
        .await?;
    let parsed: Value = serde_json::from_str(&doge).unwrap();
    println!("{:}", parsed);
    println!("{:}", parsed["version"]);
    Ok(())
}


浏览 2
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报