< 返回版块

dongdong 发表于 2019-11-18 16:44

Tags:reqwest

Cargo.toml

[dependencies]
reqwest = { version = "0.10.0-alpha.2", features = ["blocking"] }

使用了最新的版本

main.rs

extern crate reqwest;
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct Ip {
    origin: String,
}


fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp: Ip = reqwest::blocking::get("https://httpbin.org/ip")?
        .json()?;
    println!("{:?}", resp.origin);
    Ok(())
}

编译报错

error[E0599]: no method named `json` found for type `reqwest::blocking::Response` in the current scope
  --> src/main.rs:13:10
   |
13 |         .json()?;
   |          ^^^^ method not found in `reqwest::blocking::Response`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.

是Github上的官方示例有问题,还是我哪里没有引入包导致的

搜索一圈没看到相关的报错

提前感谢,走过路过帮忙解答一下 :)

评论区

写评论
作者 dongdong 2019-11-19 10:58

十分感谢,添加后解决了问题。

对以下内容的回复:

fcb1dopb 2019-11-18 21:07

reqwest = { version = "0.10.0-alpha.2", features = ["blocking","json"] } 对以下内容的回复:

fcb1dopb 2019-11-18 21:05

在Cargo.toml启用reqwest的json feature

1 共 3 条评论, 1 页