Sending various HTTP request kinds using curl
Posted by jpluimers on 2017/07/25
I’ve been using cURL but always had a feeling not to its potential basically because the cURL man page [WayBack] is both massive and lacks concrete useful practical examples.
For instance, I knew about the --header and --verbose options (I always use verbose names even though shorter -H and -v exist) to pass a specific header and get verbose output, but the man page basic examples like this by Tader:
curl --header --verbose "X-MyHeader: 123" www.google.comsource: How to send a header using a HTTP request through a curl call? – Stack Overflow [WayBack]
There are some more examples at bropages.org/curl but they’re hardly organised or documented.
So I was really glad I found the below answer [WayBack] by Amith Koujalgi to web services – HTTP POST and GET using cURL in Linux – Stack Overflow.
But first note that recent versions (around 7.22 or higher) of cURL now need to combine the --silent and --show-error (or in short -sS) parameters to suppress progress but show errors: linux – How do I get cURL to not show the progress bar? – Stack Overflow [WayBack]
Back to the examples
web services – HTTP POST and GET using cURL in Linux – Stack Overflow has these covered:
- Request types (
--requestaka-X):- GET of
- XML (with
--header). - JSON (with
--includeand--header).
- XML (with
- POST of
- parameters and
@filecontent using--dataaka-d. - form with file upload using
--form(and again@filecontent). - logging in using
--locationaka-L30x redirect following and header saving/loading using--dump-headeraka-Dand--cookieaka-b.
- parameters and
- GET of
- Saving output to a file using the
>>redirect or--outputaka-o(you might want to consider using--remote-nameaka-Ohere). - Tips for pretty printing
- JSON using
npminstalling thenodejspackagejson.pipforpythoninstalling thepjsonpackage.gemforrubyinstalling thecolorful_jsongem.- linux using the
yajl-toolspackage.
- XML using
- linux using the
libxml2-utilspackage - linux using the
tidypackage.
- linux using the
- JSON using
–jeroen
PS: Just discovered someone wrote a Unicode compatible Delphi wrapper for some of the libcurl [WayBack] functionality.






Arnaud Bouchez said
You have also a TCurlHTTP class defined in https://github.com/synopse/mORMot/blob/master/SynCrtSock.pas which works under Windows, but also under Linux, OSX and BSD via FPC.