Make a POST Request With cURL

In this guide, you will learn to Make a POST Request With cURL. As every Linux user must know, curl is the most useful Linux command. It can be used for testing API functionalities, downloading files, checking response headers, and making HTTP requests. HTTP Post request with curl is one of the common requests that is used by developers.

You can follow the steps below to use the curl command line tool for making the post requests.

Steps To Make a POST Request With cURL Examples

To complete this guide, you must have access to your server as a root or non-root user with udo privileges and follow the steps below. You can visit the Orcacore website and check for the initial server setup guides.

Step 1 – Simple Post Request with cURL

The syntax of making a post request is like the following command:

curl -X POST [option] [URL]

To perform a simple post request, you can use the following command. For example:

curl -X POST localhost:8080/tst

This will send the request and print out the response body.

Step 2 – Post Request with Data

At this point, you can add some data with the post-request command. You can specify the data option in the command. For example:

curl -X POST --data "user=tst&password=linux" localhost:8080/tst/login

Step 3 – Post Request with JSON Data

At this point, you can send a JSON Data post request with curl. You need to specify the content type header in the command. For example:

curl -X POST --data '{"Firstname": "orca", "Lastname": "core", "Email": "[email protected]", "Password": "orca"}' --H "Content-Type: application/json" localhost:8080/tst/signup

Step 4 – Post Request with Send XML Data

This will same as the JSON data. You just need to change the content type value to “text/xml” in the command to send the XML data. For example:

curl -X POST --data '{"Firstname": "orca", "Lastname": "core", "Email": "[email protected]", "Password": "orca"}' --H "Content-Type: text/xml" localhost:8080/tst/signup

Step 5 – Post Request with Send Pain text Data

Also, you can make POST requests with plain text strings. To do this, you need to use the content type header option with the text/plain option. For example:

curl -X POST --data 'orca core [email protected] orca' --H "Content-Type: text/plain" localhost:8080/tst/signup

Step 6 – Upload Data Files with cURL

Another usage of Post requests with cURL is to transfer entire files by using the form option and specifying the desired file path. For example:

curl -X POST --F file=@"home/tst/myfile.test" localhost:8080/tst/test

Also, you can transfer your desired types of data. For example, you can transfer the PDF files with the command below:

curl -X POST –F file=@"home/tst/myfile.pdf;type=application/pdf" localhost:8080/tst/test

Step 7 – Multipart Request

With the cURL utility, you can send a POST request to a form simulating multi-data form submission. For example, we send files and data to our web application’s endpoint using the form option:

curl -X POST –F file=@"home/tst/myfile.pdf;type=application/pdf" --F user="orca" --F password="linux" localhost:8080/tst/addform


At this point, you have learned to Make a POST Request With cURL. The examples provided in this guide include Simple Post Requests, Post Request with Data, Post Request with JSON Data, Send XML Data, Send Pain text Data, Upload Data Files, and Multipart Request.

Hope you enjoy it. You may be interested in these articles:

Use curl command in Linux

Make a GET Request With cURL

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!