[英]actix_web invalid header provided
I am getting this error running an actix-web based server我在运行基于 actix-web 的服务器时遇到此错误
ERROR actix_http::h1::dispatcher] stream error: Request parse error: Invalid Header provided
The handler code is this:处理程序代码是这样的:
#[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"
})
}
The headers being sent are accept, Content-Type and User-Agent.发送的标头是accept、Content-Type 和User-Agent。 I don't know how to make it work.
我不知道如何使它工作。 By the way, i'm using actix-web 4.
顺便说一句,我正在使用actix-web 4。
I tried the handler with actix
version 4
and facing no issue我尝试了使用
actix
版本4
的处理程序并且没有遇到任何问题
src/main.rs 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
}
Cargo.toml货运.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"] }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.