Using Curl -d Option

The curl -d (or --data) command line argument tells Curl to send the passed data to the server in the body of the HTTP message. When you pass data to Curl with the -d command line argument, Curl, by default, sends the data to the server in the Content-Type: application/x-www-form-urlencoded format. To send data in a different format, you must specify the correct content type with the -H command line argument. The Content-Type request header is required for servers to correctly interpret and process the data in the POST message body. In this Curl -d example, we send the data to the ReqBin echo URL. Click Run to execute the Curl -d request online and see the results.
Using Curl -d Option Run
curl https://reqbin.com/echo/post/form
	 -d "key=value&key2=value2" 
Updated: Viewed: 28051 times

What is Curl?

The Curl is a command-line utility for transmitting data to or from a remote server using one of the supported protocols. A developer uses Curl to test APIs, send requests to the server, and view server response headers. Curl supports over 25+ protocols, including HTTP, HTTPS, FTPS, FTP, and SFTP, and has built-in support for SSL certificates, web form submission, supports HTTP POST, HTTP PUT, file upload, HTTP Cookies, user authentication, and more.

What is HTTP POST request method?

The HTTP POST method is among the most widely used HTTP methods. The POST requests the web server to receive and process the data enclosed in the body message. The POST method is commonly used for uploading files and submitting HTML forms.

Curl POST request syntax

The following is an example of the syntax for a POST request with a message body:

Curl POST Request with Body
curl -X POST -H "[content type]" -d "[post data]" [options] [URL]

Where:
  • -X: the parameter specifies which HTTP request method is to be used for communication
  • -H: the content-type header indicates the type of data in the request body
  • -d: the parameter specifies the data to be sent to the server as part of the POST message

How to send data with different content-type using the curl -d command?

To send data with a different content type using the curl -d command, pass the correct Content-Type header with the -H command line argument. The following is an example of sending a Curl request with a Content-Type header:

Example of a curl -d Command
curl https://reqbin.com/echo/post/json 
   -H "Content-Type: application/json"
   -d '{"position": 1, "amount": 10}'

See also

Generate Code Snippets for Curl -d Flag Example

Convert your Curl -d Flag request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.