The above snippet represents three options required to send POST requests with cURL: -X: Specifies the request HTTP method, POST in this case. -H: For adding request headers, which are often required for POST requests. -d: For adding the cURL request body.
Common cURL POST Request Examples
Now that we have explored the syntax required for sending cURL POST requests let's apply it to common use cases.
Sending JSON Body
To pass a JSON body with cURL POST requests, we can use the the -d option followed by the data object:
Similar to the above snippet, we can send a cURL POST request with XML data through the -d option. We'll also change the Content-Type header to the equivalent of XML:
curl -X POST \
-H "Content-Type: application/xml"
-d "<?xml version="1.0" encoding="UTF-8"?><product><id>1</id><name type="title">Box of Chocolate Candy</name></product>"
https://httpbin.dev/post
Sending Files
To make cURL POST files, we can use the -F option followed by the file path to upload it:
curl -X POST -F "file=@/file/path/file.img" https://httpbin.dev/post
Note that the -F argument only accepts one file path. To pass a list of files, each file has to be attached using a dedicated argument.
Sending Form Requests
Form POST requests are commonly required to retrieve tokens or data behind forms. Let's replicate this form example using cURL POST requests:
curl -X POST \
-d 'custname=Scrapfly&custtel=&custemail=&size=small&topping=cheese&delivery=13%3A45&comments=' \
https://httpbin.dev/post
Authenticate cURL POST Requests
Let's make cURL POST requests support basic HTTP authentication. For this, we can use the basic option:
curl -X POST --user user:passwd --basic https://httpbin.dev/basic-auth/user/passwd
The response of the above cURL request indicates that it's successfully authenticated:
{
"authorized": true,
"user": "user"
}
For further details on different mechanisms for handling authentication with cURL requests, refer to our dedicated guide.
Further cURL Options
Sending cURL POST requests often require additional configuration for the request. Here are additional cURL arguments and their usage:
Argument
Full Option
Description
-x
--proxy
Use proxy with cURL, either as HTTP or SOCKS
-Z
--parallel
Send multiple cURL requests in parallel
-L
--location
Make cURL follow request redirects
-O
--output
Save the response binary data to a local directory
-I
--head
Use the request HEAD HTTP method
-b
--cookie
Add request cookies
-v
--verbose
Sends the request in verbose mode, which include further debugging details
-k
--insecure
Skip SSL verification for HTTPs connection
For further details on sending requests with cURL, refer to our dedicated guide.
In this guide, we'll explore Curlie, a better cURL version. We'll start by defining what Curlie is and how it compares to cURL. We'll also go over a step-by-step guide on using and configuring Curlie to send HTTP requests.
In this article, we'll go over a step-by-step guide on sending and configuring HTTP requests with cURL. We'll also explore advanced usages of cURL for web scraping, such as scraping dynamic pages and avoiding getting blocked.
Learn how to prevent TLS fingerprinting by impersonating normal web browser configurations. We'll start by explaining what the Curl Impersonate is, how it works, how to install and use it. Finally, we'll explore using it with Python to avoid web scraping blocking.