CURL POST Request The HTTP post request is one of the most popular HTTP/HTTPS request methods used to send data to a remote host to create or update a resource. In the above command, curl will parse the header and store the cookies received from www.example.com. Curl will send to the server the stored cookies which match the request as it follows the location. The file 'empty.txt' may be a nonexistent file.
What is CURL ?
Here I share how I using curl to POST data to our API endpoint locally (ssh to server and run the command inside). First of all, i will generated json file to use as data driven unit test and send to my server via scp: $. Curl offers a busload of useful tricks like proxy support, user authentication, ftp upload, HTTP post, SSL (https:) connections, cookies, file transfer resume and more. As you will see below, the amount of features will make your head spin! Curl is powered by libcurl for all transfer-related features. See libcurl (3) for details. Making POST requests with cURL. By default, cURL sends GET requests, but you can also use it to send POST requests with the -d or -data option. All the fields must be given as key=value pairs separated by the ampersand (&) character. As an example, you can make a POST request to httpbin.org with some parameters.
CURL is a tool for data transfer. It is also available as a library for developers and as a CLI for terminal-based use cases. Both have the same engine inside (Truth is that CLI tool is just the program that uses the library under the hood).
CURL works with every protocol you might have used. Head over this site to check whether CURL works with your target protocol or not.
What CURL can do?
Hmm… Everything that is related to data transfer. Everyone must have used a browser. Even now, you are reading this article through your browser. What browser does, it requests a page and gets it as a response. It can write and read cookies. And then it renders(displaying the content, images and executing JS scripts) it.
CURL can do everything a browser except for the last part rendering because it is not related to data transfer.
As wrap up, CURL can download HTML pages, fill HTML forms and submit them, download files from a FTP/HTTP server and upload files to the same and read/write cookies.
This makes it an excellent tool to be used in scripting, debugging and forensic analysis etc.
Curl command examples
Let’s see what can you do with Curl.
1. Get a response from a server
Everything from server is a response to the request. So getting a HTML page is same as downloading a file.
To get a HTML response from http://info.cern.c,
To get the list of posts as a response from a server ( https://jsonplaceholder.typicode.com/posts),
Since we know how to get a response from a server, you can download a file ( say Google logo ).
The Snowflake Obsidian is a stone of purity. It symbolizes the need to regularly clear your body, heart, mind, and spirit of toxins that can prevent the free flow of positive energies. The healing energies of this stone will help you achieve a balance in your body, mind, and spirit. Whatever is causing you fear, pain or worry will be removed. CraftbuddyUS 6 pcs 35mm Self Adhesive Clear Stick On Snowflake Teardrop Diamante Gems. From shop CraftbuddyUS. 5 out of 5 stars. Snowflake gem. All your worries can be resolved by this beautiful gem called “Snowflake Obsidian.” It is one such gem that allows you to halt, breathe, and understand the balance of life. Snowflake Obsidian, Gemstone Ring, Grey Black, Wire Ring, Adjustable Ring, Wire Rings, Wire Jewelry, Gemstone Rings, Stacking Rings. 5 out of 5 stars. Only 3 available and it's in more than 20 people's carts.
Above command will dump binary image data which you can’t view in the terminal. You need to save them and then use a photo viewer to see them.
Note that various option flags can be placed anywhere on the command instead of the strict ordering. So no worry if you placed any option in the last while the examples had the flag in the beginning.
2. Save the file with a default file name
Every file that is served on the internet has a filename. To use the same filename as the downloaded filename use -O flag.
3. Save the file with custom name
To save the filename with your own custom name, use -o flag followed (strictly) by a custom name.
4. Download multiple files
To download multiple files, separate them with a white space.
If you want to use -O flag for all the URL’s, use
The same workaround should be done for any flag. This is because the first occurrence of a certain flag is for the first URL, the second flag is for the second URL and so on.
5. Download a range of files
curl has the in-built ability to download a range of files from the server. This can be illustrated from the following example.
Above command downloads files from logo1.png, logo2.png, logo3.png and up to logo9.png.
6. Download a file only if latest
To download a file only if the file’s modification time is latest than the given time.
7. Resume Downloading
If you have already partially transferred a file, you can resume the transfer by using the -C flag. Offset from which transfer needs to be continued should be passed as a parameter to the -C flag.
8. Upload a file
To upload a file to the server, one needs to use -T flag followed by the file path on your local system.
9. Delete a file
To delete a file named deleteFile.txt in a server, one can use -X flag which is intended for any HTTP verb/method(like GET, POST, PUT, DELETE, PATCH). Most of the FTP servers will have configured DELETE method if not all advanced HTTP methods.
You can also modify the above command for any HTTP method to do the corresponding task. For Example, if your server allows TRUNCATE method ( this is made-up HTTP method, not a standard one) which removes only the content in the file and not the file, one can use the command similar to the below one.
Above mentioned are the main uses of curl. But there might be difficulties which needed to be fought such as redirects, user authentication, SSL certificates, etc., We can call them add-ons as they are only optional but still remain crucial for certain purposes. Let’s see some of those addons and how to handle it with curl in the next section.
![Post Post](/uploads/1/3/4/1/134199128/460242327.png)
10. Avoid redirects
When you request http://www.google.com , you will be served only the regional page such as www.google.co.in. This is done with the help of redirects (HTTP packets with status codes in the range 300-399).
You can avoid redirects with the option L.
11. Authentication
When the server is configured to serve for only certain individuals with credentials, they will be provided with username and password. One can make login with the help of -u flag.
12. Limit data transfer
If you want to impose a data transfer limit use –limit-rate flag. Following command tries to download the file with rate limit as 10K.
13. Show/Hide transfer Status
If the response is redirected from the terminal such as downloading, uploading then curl automatically shows the status/progress meter for the transfer.
If you do not want to see the progress meter, just append the command with -s flag. Progress will not be shown for response directed for the terminal. Telehandler rental.
14. Ignore SSL certificates
Do you remember the situations in which you need to give security certificate exception to visit some websites? If you trust the sources and you want to do a data transfer, you can ignore SSL certificate validation by using -k flag.
15. Get Header Information also
To display the header information along with transferred data, use the -i flag.
16. Get Header information Only
If you want only the headers and not the data, use the -I flag
17. Change User Agent
Some websites and servers don’t allow certain kinds of devices to access their systems. But how do they know that we are using a specific kind of device? This is due to the User-Agent HTTP header field. We can change this User Agent with -A flag.
18. Sending data to the Server
If the server needs some data such as token or API key, use -d flag to send the data. Data that needs to be sent should follow the flag in the command. One can use “&” to combine multiple data. This is usually done by GET and POST requests in browsers. This is one of the ways by which you can send your form information.
19. Write Cookies to a File
Cookies are some small information that allows maintaining a session with a stateless HTTP protocol. If you want to know more about Cookies, refer to this great resource.
To write cookies to a file, -c flag followed by the cookie filename should be used.
20. Reading Cookies from a File
Curl Send Post Form Data
To read a cookie from the file, -b flag followed by cookie filename can be used.
Note that -b flag only reads the cookie from the file. So if the server resends another cookie, you might need to use -c option to write them.
21. Start a new Session
If you want to initiate a new session by discarding the cookies, use -j flag. It starts a new session even if you have provided the cookie file to read with -b flag.
Congratulations! You made it to the end. If you find this article useful, share it with your friends and follow us on Social media. If you have any suggestions about this article or any other topic, feel free to drop them below.
Become a Member for FREE
Become a member to get the regular Linux newsletter (2-4 times a month) and access member-only contents.
![Curl Send Post Curl Send Post](/uploads/1/3/4/1/134199128/791027871.jpg)
Curl Send Post Request
Join the conversation.