我正在用Rust编写一些Web api。我使用XMLHttpRequest从JavaScript发送Unit8Array,我需要在服务器中以字节为单位读取它们。
我的服务方法的声明是:
pub fn user_login_bin(mut req: HttpRequest) {
println!("{:?}", req);
let mut stream = req.take_payload().take();
// error label: method not found in `actix_http::payload::Payload<()>`
let item = stream.poll().unwrap();
println!("{:?}", item);
HttpResponse::Ok().into()
}
我如何从actix_web :: HttpRequest有效内容中读取Vec?
我尝试了一些示例代码,但是它也不起作用:
req.take_payload()
// error label: method (fold) not found in `actix_http::payload::Payload<()>`
.fold(BytesMut::new(), move |mut body, chunk| {
body.extend_from_slice(&chunk);
Ok::<_, Error>(body)
})
.and_then(|bytes| {
println!("request body: {:?}", bytes);
});
答案 0 :(得分:1)
字节提取器工作正常
pub fn user_login_bin(req: HttpRequest, body: Bytes) -> HttpResponse {
println!("{:?}", req);
println!("{:?}", body);
HttpResponse::Ok().into()
}