How to cURL POST from the Command Line

Jan 30, 2017 - 9 Comments

curl post request command line syntax

Curl is the powerful command line utility that allows you to transfer data to or from a server or URL. One common function used by developers is to make a POST request with curl, which is what we’re going to cover here.

We’ll keep things fairly simple and show three examples to make a POST request with curl from the command line, with syntax with and without data, and also to a form.

cURL POST Request Command Line Syntax

You can make a curl POST request with or without data, depending on what you’re attempting to do. Remember that using proper syntax capitalization matters.

curl post request with no data:

curl -X POST http://URL/example.php

curl post request with data:

curl -d "data=example1&data2=example2" http://URL/example.cgi

curl POST to a form:

curl -X POST -F "name=user" -F "password=test" http://URL/example.php

curl POST with a file:

curl -X POST -F "image=@/path/example.gif" http://URL/uploadform.cgi

Similarly, you can also download files with curl too by using a different command string.

curl POST JSON data

curl -H "Content-Type: application/json" -X POST -d '{"user":"bob","pass":"123"}' http://URL/

Terminal in macOS

For further curl specifics or details, refer to the curl manual or help page:

curl --help

curl --manual

Know of a better way to make a post request with cURL? Let us know in the comments. You can also check out some interesting specific uses of the curl command here.


Related articles:

Posted by: Paul Horowitz in Command Line, Tips & Tricks


» Comments RSS Feed

  1. EFeragen says:

    Finally got that function app to spin around locally from the command line.

  2. Irv says:

    Thank you, I was able to post to a MS Teams channel from the command line using your examples.

  3. Nabin Poudel says:

    Very interesting reading now it will be easier for me to automate sending emails.

  4. Ian says:

    Thanks for the article, working a blog backend and this is pretty useful for testing it

  5. curly says:

    this is useful for more curl post request info as well

  6. D says:

    Well that was useless. Anyone can list a series of commands. To be useful you need to give some actual examples of how you would use this in context.

    • Your comment is useless. To be useful you would need to offer some actual information or insight into the topic that is being discussed and how it relates to the context.

      curl is probably way over your head, stick with the iPad then you won’t need to get your hands dirty.

      • Nob Oddy says:

        Your comment manages to be both useless and also condescending, congratulations! Don’t forget to collect your internet points on the way out.

    • DD says:

      I totally agree, completely useless.

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site