4

hyperを使用して http-client を構築しています。そして、メソッドpostでjsonデータを送信しようとします:

fn run_client() {

    let json = json!({
                        "list": [
                        {
                          "id": 1,
                          "price": 10,                                
                        },
                        {
                          "id": 2,
                          "price": 20,
                        }]
                    }
    );

    let mut core = Core::new().unwrap();
    let client = Client::new(&core.handle());

    let uri = "http://127.0.0.1:8888/add".parse().unwrap();

    let mut req = Request::new(Method::Post, uri);

    req.headers_mut().set(ContentType::json());
    req.set_body(json);

    let post = client.request(req).and_then(|res| {
        println!("POST: {}", res.status());

        res.body().concat2()
    });

    core.run(post).unwrap();
}

しかし、エラーが発生します:

the trait `std::convert::From<serde_json::Value>` is not i mplemented for `hyper::Body`

どうすればそれを修正し、serde_json::Valueハイパークライアントでデータを送信できますか?

4

1 に答える 1