Rust 从“发出post请求时,请求正文为空”;reqwest“;板条箱锈蚀
我正试图用一箱锈迹斑斑的东西提出邮寄要求。下面是cargo.toml的片段Rust 从“发出post请求时,请求正文为空”;reqwest“;板条箱锈蚀,rust,rust-cargo,rust-tokio,reqwest,Rust,Rust Cargo,Rust Tokio,Reqwest,我正试图用一箱锈迹斑斑的东西提出邮寄要求。下面是cargo.toml的片段 [dependencies] tokio = { version = "0.2", features = ["full"] } reqwest = { version = "0.10", features = ["json"] } 下面是我向simple server发出请求的代码片段 use reqwest::{Response, StatusCode}; use serde_json::{json, Value};
[dependencies]
tokio = { version = "0.2", features = ["full"] }
reqwest = { version = "0.10", features = ["json"] }
下面是我向simple server发出请求的代码片段
use reqwest::{Response, StatusCode};
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result< (), reqwest::Error> {
let map1 = json!({
"abc":"abc",
"efg":"efg"
});
let body: Value = reqwest::Client::new()
.post("http://localhost:4000/hello")
.json(&map1)
.send()
.await?
.json()
.await?;
println!("Data is : {:?}", body);
Ok(())
}
我得到的结果是:
Request received POST /hello []
所需的输出是字节的向量数组,但我收到的是一个空向量数组
我已经尝试过的解决方案有:
- 使用Postman向同一服务器发出post请求,并且工作正常
- 使用相同的reqwest代码向任何其他服务器(如hyper、actix等)发出post请求,并且工作正常
- 将简单正文作为post请求正文发送(无JSON)。但同样的问题也发生了
每一个有价值的建议都会得到鼓励。我试着连续提出几个请求(使用
wget--post file=…
),结果似乎是随机显示数据或空结果。听起来像是simple server
@Jmb中的一个bug,你说得对。我也有同样的感觉,有时会起作用。很可能是个虫子。
Request received POST /hello []