rust-httpc-test icon indicating copy to clipboard operation
rust-httpc-test copied to clipboard

How to do a traditional POST request with form data

Open jaredtmartin opened this issue 1 year ago • 2 comments

I love your videos, and I like this tool, but I'm working with HTMX and I need to be able to do post requests with form data.
Currently I'm trying this:

        let req_login = hc.do_post(
		"/login",
		json!({
			"username": "demo1",
			"pwd": "welcome"
		}),
	);
	req_login.await?.print().await?;

But I'm getting:

=== Response for POST http://localhost:8080/login
=> Status         : 415 Unsupported Media Type Unsupported Media Type
=> Headers        :
   content-type: text/plain; charset=utf-8
   content-length: 73
   date: Thu, 01 Feb 2024 19:06:56 GMT
=> Response Body  :
Form requests must have `Content-Type: application/x-www-form-urlencoded`
===

I don't see any related examples in the docs.

jaredtmartin avatar Feb 01 '24 19:02 jaredtmartin