expression
Encode form data
A form uses application/x-www-form-urlencoded encoding, which differs from JSON. Match the body representation to the receiving endpoint contract. External crate example; constructs requests or synthetic responses in memory; no request is sent. Expected stdout (not executed): application/x-www-form-urlencoded q=red+blue Common mistake: Sending form encoding to an endpoint requiring JSON.
Formal Syntax & Structure
rust syntaxrust
builder.form(&[(key, value)])Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let c = reqwest::Client::builder().no_proxy().build().unwrap(); let r = c.post("https://example.com/search").form(&[("q", "red blue")]).build().unwrap(); println!("{}", r.headers()["content-type"].to_str().unwrap()); println!("{}", std::str::from_utf8(r.body().unwrap().as_bytes().unwrap()).unwrap());}