How to cURL POST from the Command Line

Jan 30, 2017 - 5 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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

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

5 Comments

» Comments RSS Feed

  1. 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.

    • DD says:

      I totally agree, completely useless.

  2. curly says:

    this is useful for more curl post request info as well

    https://curl.haxx.se/docs/httpscripting.html#POST

  3. Ian says:

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

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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