如何从 actix_web::HttpRequest 获取(二进制)有效负载

How to get (binary) payload from actix_web::HttpRequest

我正在用 Rust 写一些网页 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);
    });

字节提取器工作正常

pub fn user_login_bin(req: HttpRequest, body: Bytes) -> HttpResponse {
   println!("{:?}", req);
   println!("{:?}", body);

   HttpResponse::Ok().into()
}