我想使用超0.11.2阅读POST JSON。在“已达到”打印后,我没有看到任何事情发生。如何阅读hyper中的请求体?
fn call(&self, req: hyper::server::Request) -> Self::Future {
let mut response: Response = Response::new();
match (req.method(), req.path()) {
(&Method::Post, "/assests") => {
println!("Reached ... "); //POST: 200 OK
//let (method, uri, _version, head
let mut res: Response = Response::new();
if let Some(len) = req.headers().get::<ContentLength>() {
res.headers_mut().set(len.clone());
}
println!("Reached xxx {:?}", req.body());
res.with_body("req.body()");
}
_ => {
response.set_status(StatusCode::NotFound);
}
};
futures::future::ok(response)
}
输出:
Reached ...
Reached xxx Body(Body { [stream of values] })
请提供[MCVE]。事实上,我们必须猜测“Self :: Future”是什么,以及其他许多应用程序。 – Shepmaster
此外,这将是很好的解释你不明白从[超文本流的例子](https://hyper.rs/guides/server/echo/),它看起来应该是一个从容易的地方开始。 – Shepmaster