【发布时间】:2018-02-23 07:11:44
【问题描述】:
我有一个带有hyper 的http 客户端。我尝试使用 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 数据?
【问题讨论】:
-
我知道这不能回答您的问题,但也有reqwest。它会为您处理所有这些。