Skip to main content

fetch_post_data

Function fetch_post_data 

Source
pub async fn fetch_post_data(req: Request<Body>) -> Result<Value, String>
Expand description

从请求中获取合并参数(body + query)

对齐 PHP $this->request->param():合并 POST body 和 GET query, body 中的字段优先级高于 query。

§参数

  • reqaxum::http::Request<Body>

§返回

  • Ok(Value::Object):合并后的 JSON Object
  • Err(String):body 不可读或 JSON 解析失败

§行为

  1. 解析 query string 为 Value::Object(每个键值对均为字符串)
  2. 读取 body bytes
  3. 如果 Content-Type 为 application/json,解析 body 为 JSON 并合并到 query
  4. 如果 Content-Type 为 application/x-www-form-urlencoded,解析为表单并合并
  5. body 字段覆盖 query 字段