If you’re a developer working with APIs, learning how to send POST requests using cURL is a mandatory thing. It is one of the most easiest ways to test endpoints, upload data or interact with servers, all from your terminal.
In this post, we will show you how to send POST requests using cURL, how to send JSON, XML, files, form data.
Step 1: Is cURL Installed?
Most systems already have cURL. To check if yours does, open a terminal and run the command below:
curl --version
If it’s not installed, download it from curl.se. Windows users may need Git Bash or WSL to get the best results.
Step 2: A Simple POST Request
Here is a basic example of a POST request using cURL:
curl -X POST -d "Hello" https://example.com/api
-X POST
= HTTP method-d
= data you’re sending in the body
Step 3: Add Content-Type Headers
To inform the server what kind of data you are sending, make sure to include a Content-Type
header:
For plain text:
curl -X POST -H "Content-Type: text/plain" -d "Hello" https://example.com/api
For JSON:
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"Alice","age":30}' https://example.com/api
Use single quotes to wrap JSON so your terminal doesn’t get confused by inner double quotes.
Step 4: Send XML Payloads
If the API expects XML:
curl -X POST -H "Content-Type: application/xml" \
-d '<?xml version="1.0"?><user><name>Alice</name></user>' \
https://example.com/api
Step 5: Upload Files with -F
To upload files (like images, documents, or logs):
curl -X POST -F "file=@/path/to/file.jpg" https://example.com/upload
Upload multiple files:
curl -X POST \
-F "image1=@/path/to/one.jpg" \
-F "image2=@/path/to/two.jpg" \
https://example.com/upload
cURL automatically handles multipart/form-data
for you.
Step 6: Send Form Data
For classic form-style submissions (like logging in or submitting a contact form):
curl -X POST -d "username=test&password=1234" https://example.com/login
You can also pass multiple form fields with repeated -d
flags or combine them into one string.
Step 7: Add Basic Authentication
If the endpoint requires login credentials, use -u
:
curl -u username:password https://example.com/secure
This adds an Authorisation
header automatically using Base64 encoding.
Using cURL with Residential Proxies
If you’re testing geo-targeted endpoints or want extra privacy, you can use cURL with a proxy like this:
curl -x http://proxyuser:[email protected]:port \
-X POST -d '{"action":"test"}' https://example.com/api
At Thunderproxy.com, we provide residential proxies that work perfect with cURL. This is helpful when testing websites from different locations or when you need to bypass rate limits.
Final Thoughts
cURL is a tool for developers, system administrators and testers. It’s fast and efficient – whether you are sending JSON, uploading files, or logging into protected endpoints.
Once you learn the basic flags (-X
, -d
, -H
, -F
, -u
), you’ll be comfortable to create any kind of HTTP request in seconds.