actix_web 提供的标头无效

fer*_*ale 6 rust actix-web

我在运行基于 actix-web 的服务器时遇到此错误

ERROR actix_http::h1::dispatcher] stream error: Request parse error: Invalid Header provided
Run Code Online (Sandbox Code Playgroud)

处理程序代码是这样的:

#[derive(Serialize, Deserialize)]
pub struct Data {
   some_data: String
};
async fn handler_post(
  request: HttpRequest,
  data: web::Json<Data>
) -> impl Responder {
  HttpResponse::OK()
     .json(ApiResponse {
        status: "success"
     })
}
Run Code Online (Sandbox Code Playgroud)

发送的标头包括 Accept、Content-Type 和 User-Agent。我不知道如何让它发挥作用。顺便说一句,我正在使用 actix-web 4。

Cha*_*dan 1

actix我尝试了版本处理程序4,没有遇到任何问题

src/main.rs

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest};
use serde::{Serialize, Deserialize};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello world!")
}

#[derive(Serialize, Deserialize)]
pub struct Data {
   some_data: String
}

#[derive(Serialize, Deserialize)]
pub struct ApiResponse<'a> {
   status: &'a str
}

#[post("/")]
async fn handler_post(
  request: HttpRequest,
  data: web::Json<Data>
) -> impl Responder {
  HttpResponse::Ok()
     .json(ApiResponse {
        status: "success"
     })
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(hello)
            .service(handler_post)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}
Run Code Online (Sandbox Code Playgroud)

Cargo.toml

[package]
name = "..."
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
serde = { version = "1.0", features = ["derive"] }
Run Code Online (Sandbox Code Playgroud)