Вход

How to Use cURL to Send POST Requests

tutorials

Last updated: July 7th, 2025

TPThunderproxy Team

If you’re working with APIs, learning how to send POST requests using cURL is a must. It’s one of the most straightforward ways to test endpoints, upload data, or interact with servers — all from your terminal.

In this post, we’ll show you how to send POST requests using cURL, including how to send JSON, XML, files, form data, and more.

Step 1: Is cURL Installed?

Most systems already have cURL. To check, run:

curl --version

If it’s not installed, grab it from curl.se. Windows users may need Git Bash or WSL for best results.

Step 2: A Simple POST Request

Here’s the most 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 tell the server what kind of data you’re sending, 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.

Bonus: Using cURL with 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:proxypass@proxy.thunderproxy.com:port \
-X POST -d '{"action":"test"}' https://example.com/api

At Thunderproxy.com, we provide residential proxies that work perfectly with cURL. This is especially helpful when testing from different locations or bypassing rate limits.

Final Thoughts

cURL is a go-to tool for developers, sysadmins, and testers. It’s fast, lightweight, and gets the job done — whether you’re sending JSON, uploading files, or logging into protected endpoints.

Once you learn the basic flags (-X-d-H-F-u), you’ll be comfortable crafting any kind of HTTP request in seconds.

Ready to try it yourself?

Get started with our product in just a few clicks.