我正在尝试使用Rocket crate创建后端:
fn main() {
rocket::ignite().mount("/", routes![helloPost]).launch();
}
#[derive(Debug, PartialEq, Eq, RustcEncodable, FromForm)]
struct User {
id: i64,
USR_Email: String,
USR_Password: String,
USR_Enabled: i32,
USR_MAC_Address: String
}
#[post("/", data = "<user_input>")]
fn helloPost(user_input: Form<User>) -> String {
println!("print test {}", user_input);
}
当我运行cargo run
一切正常但是,当我使用邮递员发送 POST 请求进行测试时,我收到此错误:
POST /:
=> Matched: POST / (helloPost)
=> Warning: Form data does not have form content type.
=> Outcome: Forward
=> Error: No matching routes for POST /.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
我已将标头内容类型设置为 JSON 和其他可用的语言,但使用 Rocket 我无法让它工作。
这是我的 JSON 正文:
{
"USR_Email": "test@test.it",
"USR_Password": "500rockets",
"USR_Enabled": 0,
"USR_MAC_Address": "test test"
}
如何解决这个问题?