How to Send POST Requests With cURL


Yelyzaveta Hayrapetyan
Last updated on
2025-06-27
3 min read
Yelyzaveta Hayrapetyan
Last updated on
2025-06-27
3 min read
In this tutorial, you're going to learn how to send cURL POST requests. cURL is a powerful command-line tool for transferring data over various network protocols, including HTTP, HTTPS, FTP, and more. Since POST is a request method of HTTP & HTTPS protocols, cURL POST request is a one-line command that you can easily run in your terminal.
First, install cURL if you haven't installed it already. You can find the installation instructions in our How to Use cURL With Proxy blog post. Next, take a look at the table below:
Flag | Option | Argument | What it does |
---|---|---|---|
-X | --request | POST |
Specifies HTTP method |
-H | --header | User Agent: Chrome |
Specifies Header content/type |
-F | --form | file=@/path/file.jpg |
Attach form data or files. |
-u | --user | username:password |
Set credentials |
-d | --data | data |
Sets the request POST data in message body |
-v | --verbose | N/A | Display information about request & response |
This table represents all the necessary command-line options of the cURL command that you'll be using in the next few sections. You don't need to memorize all of them right away, just briefly go over them. Once you start to use cURL requests daily, they'll become part of your muscle memory while working in a terminal. And whenever you need, you can always access all the available cURL options including the above using the --help option for more detailed descriptions:
curl --help
The basic cURL POST request syntax is as below:
curl -X POST -d "Hello" https://example.com/api
Notice the -X flag followed by POST. It tells cURL to make a POST request using the typical HTTP POST method, and the -d flag sets request data as Hello and sends it to the HTTP server at https://example.com/api. The -X flag is the short form of the command line option --request. Check out the above table for learning all the long forms of the various command line options.
Like any HTTP request, cURL POST requests can also have custom headers. Here, using the header flag will force cURL to use any specific Content-Type header of your choice.
curl -X POST -H "Content-Type: text/plain" -d "Hello" https://example.com/api
In the above cURL POST command, there's an additional -H flag that lets users send custom HTTP request headers via cURL. In this case, by specifying the Content-Type header as text/plain you’re letting the web server know that the request body data is in TEXT format.
It’s also possible to send JSON data in the cURL POST request body. All you need to do is set the appropriate Content-Type header and pass the JSON body with either the -d flag or cURL --data option. This command will make a cURL POST request with the JSON format data specified in the argument.
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://example.com/api
If you need a straightforward way to create a JSON code from a cURL command, use this cURL to JSON converter.
Similar to JSON data, you can also use cURL POST with body in XML format. You'll have to make changes to the request header and set it to application/xml.
curl -X POST -H "Content-Type: application/xml" -d '<?xml version="1.0" encoding="UTF-8"?><root><name>John Doe</name><age>30</age></root>' https://example.com/api
To send form data or a file via cURL POST, you'll have to use the -F flag. Pay attention to the capitalization of the letter “F”. All of the cURL flags or command-line options are case-sensitive and should look like the following cURL POST example:
curl -X POST -F "file=@/path/to/img.png" https://example.com/api/upload
As you can see, the above cURL POST request is uploading an image local file. Right after the -F the path of the image was given. Keep in mind cURL supports both local and remote file transfers. You can also use multiple -F flags to send multiple files to the server as shown below:
curl -X POST -F "file=@/path/to/img1.png" -F "file=@/path/to/img2.png" https://example.com/api/upload
The same HTTP request methods apply when working with form data, where you can specify each form field individually. This way, you can send form data, including binary data, and cURL will handle the completed transfer automatically.
You can use the -u flag or the --user option to specify the username & password for basic authentication. cURL will automatically create the Authorization header based on the received data.
curl -u username:password https://example.com/login
You’ll have to replace username and password with the actual authentication credentials. Also, don’t forget to replace the example URL with your own when making cURL requests.
cURL is a lightweight yet powerful tool for sending POST requests from CLI. With just a single line of command, you can easily transmit data in various formats such as JSON, XML, or file uploads and form data. cURL's simplicity and flexibility make it a popular choice for developers. While it may not offer a graphical interface, cURL provides a versatile and efficient way to interact with servers. Whether you're a seasoned developer or a complete beginner, mastering cURL is a valuable skill that’ll help you in various stages of your career. If you're new to cURL, we recommend reading our article on how to send GET requests with cURL or trying our cURL converter tool.
You can also check out the How to Use cURL With REST API and How to Use cURL With Python articles available on our blog. Additionally, you can learn how to use cURL OPTIONS requests for web scraping. As usual, if you have any questions, please contact us at hello@oxylabs.io or via the live chat – our professional team is always ready to provide you with the needed assistance.
Test Oxylabs Scraper APIs designed for advanced web scraping tasks:
A cURL POST refers to a POST request made using cURL. cURL is a versatile and widely used CLI that allows you to make HTTP requests. When making a POST request with cURL, you're sending data to a server or an API. The data is typically included in the body of the request. By using cURL's -X POST option and providing the necessary data and URL, you can initiate a POST request.
Absolutely. cURL has all the necessary features to make HTTP requests. If you're familiar with the Command line interface and prefer working with command line tools, then cURL’s lightweight CLI will be immensely helpful. However, cURL doesn’t have a GUI like Postman. Also, some of the advanced features of Postman such as the history of requests, test automation, team collaboration, etc. are not available in cURL.
Both Postman & Insomnia are popular among developers as an alternative to cURL. These two libraries can also make POST requests. You can also use Python or other Scripting Languages such as Ruby, Go, etc. All these Programming languages have HTTP libraries to send GET & POST requests.
GET and POST both serve distinct purposes in cURL. They differ primarily in how data is transmitted to the server or API. The GET method relies on URL parameters and queries to send data and retrieve information. On the other hand, the POST method sends data through the request body, which hides data from the URL. As a result, the POST method is considered more secure than GET, making it a preferred HTTP method for transmitting sensitive information.
To send a POST request in CMD, use cURL with the -X POST option and the -d flag to include data. For example, you can run curl -X POST -d "Hello" followed by the target URL. If you're sending JSON or XML remember to add the Content-Type header.
Both PUT and POST are used to send data to a server, but they have different use cases. POST is mostly used to create a new resource on the server by sending data, while PUT is used to update or replace an existing one. Both methods use similar cURL syntax, -X PUT for PUT requests and -X POST for POST requests.
cURL is neither GET nor POST, but it's a command-line tool that includes various HTTP methods like GET, POST, PUT, DELETE, and more. By default, when you use cURL without specifying a method, it performs a GET request. However, you can specify different HTTP methods using the -X flag. For example, -X POST makes it a POST request, -X PUT makes it a PUT request, and so on.
About the author
Yelyzaveta Hayrapetyan
Senior Technical Copywriter
Yelyzaveta Hayrapetyan is a Senior Technical Copywriter at Oxylabs. After working as a writer in fashion, e-commerce, and media, she decided to switch her career path and immerse in the fascinating world of tech. And believe it or not, she absolutely loves it! On weekends, you’ll probably find Yelyzaveta enjoying a cup of matcha at a cozy coffee shop, scrolling through social media, or binge-watching investigative TV series.
All information on Oxylabs Blog is provided on an "as is" basis and for informational purposes only. We make no representation and disclaim all liability with respect to your use of any information contained on Oxylabs Blog or any third-party websites that may be linked therein. Before engaging in scraping activities of any kind you should consult your legal advisors and carefully read the particular website's terms of service or receive a scraping license.
Web Scraper API for scalable data collection
Choose Oxylabs' Web Scraper API to gather real-time public data hassle-free.
Get premium Oxylabs proxies
Forget about IP blocks and CAPTCHAs with 175M+ premium proxies located in 195 countries.
Get the latest news from data gathering world
Scale up your business with Oxylabs®
Proxies
Advanced proxy solutions
Data Collection
Datasets
Resources
Innovation hub
Web Scraper API for scalable data collection
Choose Oxylabs' Web Scraper API to gather real-time public data hassle-free.
Get premium Oxylabs proxies
Forget about IP blocks and CAPTCHAs with 175M+ premium proxies located in 195 countries.