Back to blog

How to Send POST Requests With cURL

How to Send POST Requests With cURL
author avatar

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.

Tutorial: Sending POST requests

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.

Specifying the Content-Type

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. 

Posting JSON

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.

Posting XML

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

Sending a file/multiple files via POST

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.

Sending authentication credentials

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.

Conclusion

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. 

Try Oxylabs Scraper APIs

Test Oxylabs Scraper APIs designed for advanced web scraping tasks:

  • 5K requests for free
  • No credit card is required

Frequently asked questions

What is a cURL POST?

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.

Can I use cURL instead of Postman?

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. 

What are the alternatives to cURL POST?

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.

What is the difference between POST and GET cURL?

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.

How do you cURL a POST in CMD?

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.

What is the difference between cURL PUT and POST?

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.

Is cURL a GET or POST?

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

author avatar

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.

Related articles

How to Send HTTP Headers With cURL
How to Send HTTP Headers With cURL
author avatar

Augustas Pelakauskas

2025-06-27

Python request library
Python Requests Library: 2025 Guide
Authors avatar

Adomas Sulcas

2025-01-02

How to Send GET Requests With cURL
How to Send GET Requests With cURL
Iveta Vistorskyte avatar

Iveta Vistorskyte

2023-06-09

Web Scraper API for scalable data collection

Choose Oxylabs' Web Scraper API to gather real-time public data hassle-free.

Web Scraping API

Get premium Oxylabs proxies

Forget about IP blocks and CAPTCHAs with 175M+ premium proxies located in 195 countries.

Residential proxies

Get the latest news from data gathering world

I’m interested

Web Scraper API for scalable data collection

Choose Oxylabs' Web Scraper API to gather real-time public data hassle-free.

Web Scraping API

Get premium Oxylabs proxies

Forget about IP blocks and CAPTCHAs with 175M+ premium proxies located in 195 countries.

Residential proxies