[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedSeptember 11, 2023

How to make a POST request with cURL.

How To Make A POST Request With CURL.

In this article, we’re going to explain how to use cURL to make POST requests. The HTTP POST method is used to send data to the remote server.

cURL is a command-line utility for transferring data from or to a remote server using one of the supported protocols. It is installed by default on macOS and most Linux distributions.

 

Making a POST request

The general form of the curl command for making a POST request is as follows:

curl -X POST [options] [URL]

The type of the request body is indicated by its Content-Type header.

Generally, a POST request is sent via an HTML form. The data send to the form is usually encoded in either multipart/form-data or application/x-www-form-urlencoded content type.

To create a POST request, use the -F option, followed by the field=value pair. The following example shows how to make a POST request to a form that has “name” and “email” fields:

curl -X POST -F 'name=nexonhost' -F '[email protected]' https://example.com/contact.php

When the -F option is used, curl sends the data using the multipart/form-data Content-Type.

Another way to make a POST request is to use the -d option. This causes curl to send the data using the application/x-www-form-urlencoded Content-Type.

curl -X POST -d 'name=nexonhost' -d '[email protected]' https://example.com/contact.php

If the -d option is used more than once you can merge the data using the & symbol:

curl -X POST -d 'name=nexonhost&[email protected]' https://example.com/contact.php

 

Specifying the Content-Type

To set a specific header or Content-Type use the -H option. The following command sets the POST request type to application/json and sends a JSON object:

curl -X POST -H "Content-Type: application/json" \
    -d '{"name": "linuxize", "email": "[email protected]"}' \
    https://example/contact

 

Uploading Files

To POST a file with curl, simply add the @ symbol before the file location. The file can be an archive, image, document, etc.

curl -X POST -F 'image=@/home/user/Pictures/wallpaper.jpg' http://example.com/upload

 

Conclusion

We’ve shown you how to use curl to make POST requests. For more information about curl, visit the Curl Documentation page.

Keep reading
How to use mount command in Linux.
September 13, 2023

How to use mount command in Linux.

How To Use Mount Command. The Linux file system hierarchy is arranged in a tree, with the file system starting from the root directory (/). All other child file systems branch out from the root directory. The mount command allows users to mount, i.e., attach additional child file systems to a…

Read article
How to use zcat command in Linux.
September 13, 2023

How to use zcat command in Linux.

How To Use Zcat Command. The “zcat” command in Linux is a tool for displaying the contents of compressed files in the “gzip” format. It is similar to the “cat” command, which is used for indicating the contents of regular text files, but it is specifically designed for working with compressed files.

Read article
How to use cal command in Linux.
September 13, 2023

How to use cal command in Linux.

What is cal command? Sometimes, you might want to have a peek at the year’s calendar or even narrow it down to a month’s calendar. The Linux cal command is an excellent built-in tool that displays a calendar of a given year or month depending on the options passed. How Does cal Command Work?…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00