The intersection of technology and leadership

Scripting web applications with cURL

I first used cURL on a project a few years ago whilst testing a RESTful applciation. It’s a really great tool and plenty of options to do things. I however, keep forgetting some of the simple commands you might use to interact with a RESTful, or even just a web application. This is really good if you want to test AJAX resources as well.

I’m putting the examples I’ve used the most up here for easy reference. You might even find it handy as well.

Perform a HTTP GET instead of POST

curl -G -F "formParamName=@fileToSendOnDisk.txt" http://localhost/someGetUri

Sending the contents of a file from disk as part of FORM data

curl -F "formParamName=@fileToSendOnDisk.txt" http://localhost/someUri

Note that the @ is very important here. You can use curl to give it content type as well.

curl -F "formParamName=@fileToSendOnDisk.json;type=text/json" http://localhost/someUri

Sending form post data as a single string

curl -d "param1=value1&param2=value2" http://localhost/someUri

Send some form post data and print the HTTP response code as the last row to the console

url -d "param1=value1&param2=value2" http://localhost/someUri -w "%{http_code}\n"

Post data to a HTTPs endpoint ignoring self-signed certificates

curl -d "param1=value1&param2=value2" https://localhost/someUri -k

Follow redirects, printing out response code and URL that was last fetched after posting data

curl -d "param1=value1&param2=value2" http://localhost/someUri -k -w "%{http_code}\n%{url_effective}\n" -L

Hope you find this useful although you can find a much larger manual in the man page, or on this site here.


  1. Artem Marchenko

    Thanks, Patrick!

    Just today I was wondering about the command-line arguments for showing HTTP response code and within few hours I’ve got this answer to my RSS reader 🙂

  2. Patrick

    Glad that it helped!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 patkua@work

Theme by Anders NorenUp ↑