W3docs

curl posting with header application/x-www-form-urlencoded

To make a POST request using curl and include a header of Content-Type: application/x-www-form-urlencoded, you can use the following command:

To make a POST request using curl and include a header of Content-Type: application/x-www-form-urlencoded, you can use the following command:

Example of curl POST request with header application/x-www-form-urlencoded

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "key1=value1&key2=value2" http://example.com

This will send a POST request to http://example.com with a body that is encoded as application/x-www-form-urlencoded and two form fields: key1 with a value of value1, and key2 with a value of value2.

You can also specify the form fields using the -F option, which automatically sets the Content-Type to multipart/form-data:

curl -X POST -F "key1=value1" -F "key2=value2" http://example.com

This sends a multipart/form-data request. Use -d for standard URL-encoded form submissions, and -F when you need to upload files or prefer a different encoding format.