How to use the cURL command to do a POST data to fields on Linux or Unix

www.lau‮tt‬uri.com
How to use the cURL command to do a POST data to fields on Linux or Unix

To use the cURL command to do a POST request with data to fields on a Linux or Unix system, you can use the following syntax:

curl -X POST -d "field1=value1&field2=value2" http://example.com/form

This will send a POST request to the http://example.com/form URL with the data field1=value1 and field2=value2 in the request body.

You can also specify the data in a separate file and use the --data-binary option to read the data from the file. For example:

curl -X POST --data-binary "@data.txt" http://example.com/form

This will send a POST request to the http://example.com/form URL with the data from the data.txt file in the request body.

You can also specify the content type of the data using the -H option. For example:

curl -X POST -H "Content-Type: application/json" -d '{"field1":"value1","field2":"value2"}' http://example.com/form

This will send a POST request to the http://example.com/form URL with the data {"field1":"value1","field2":"value2"} in the request body and the content type application/json.

Note: The cURL command is a powerful tool for transferring data over the network. It supports a wide range of protocols and options that allow you to customize the request and response. Consult the cURL man page or online documentation for a complete list of options and usage examples.

Created Time:2017-10-29 22:08:40  Author:lautturi