To send form data in a POST request using cURL, follow these steps:
Content-Type
header to application/x-www-form-urlencoded
to indicate that the data being sent is URL-encoded form data.field1=value1&field2=value2&...
. Make sure to properly URL-encode each field and value.-d
or --data
option followed by the form data string to specify the data that should be sent in the request body.-X POST
option to specify the HTTP method as POST.Here's an example cURL command to send form data in a POST request:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "field1=value1&field2=value2" \
http://example.com/endpoint
Replace field1
, field2
, value1
, value2
, and http://example.com/endpoint
with your actual form field names, values, and target endpoint URL.
Note: If the form data contains special characters that need to be URL-encoded, such as spaces or ampersands, you can use the --data-urlencode
option instead of -d
to automatically encode the form data:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "field1=value 1" \
--data-urlencode "field2=value&2" \
http://example.com/endpoint
This command automatically URL-encodes the values value 1
and value&2
in the form data.