Curl from command line
Curl is a way of making web requests from the command line. I only do this under linux, and if you don’t know why you’d want to do that, then you probably don’t need to read any further (although, that would also make an interesting article!).
Will give you the output that would be sent to your browser if you requested the main page of this site from there.
Verbose output (-v)
This is where it gets interesting, you can see the actual information being included with the HTTP request when you use the verbose switch.
curl -v http://www.lornajane.net
Try it – you see the headers and the client/server negotiation. Stuff like cache information, browser identification, and cookie information all gets transmitted in these headers.
Using HTTP verbs (-X) and data (-d)
Curl can make requests and include data with them. It can use GET as you’d expect, but POST, PUT and DELETE are all supported too.
curl -X GET "http://www.example.com?page=2&category=toys"
I’ve added the quotes because the ampersand confuses the command line
curl -X POST http://www.example.com/registration.php -d username=lornajane -d password=password -d phone=0123456789
PUT and DELETE can be done in the same way, just using the -X switch.
Actually, if you’ve got this far then you know what you’re doing – use the curl manpage for information on the other switches. Curl can do more things than I think I would ever want to do, not just HTTP, and can spoof cookies and all sorts of other good things. Its especially good for testing web services as it allows clearer diagnosis of the exact behaviour and response. Don’t tell anyone but I have also been known to vardump in the middle of webservices when debugging, and using curl lets you see the output “as it comes” – very handy!
Update: I wrote a follow-up post about Using Cookies with Curl