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" http://www.google.com
source: 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 (
--request
aka-X
):- GET of
- XML (with
--header
). - JSON (with
--include
and--header
).
- XML (with
- POST of
- parameters and
@file
content using--data
aka-d
. - form with file upload using
--form
(and again@file
content). - logging in using
--location
aka-L
30x redirect following and header saving/loading using--dump-header
aka-D
and--cookie
aka-b
.
- parameters and
- GET of
- Saving output to a file using the
>>
redirect or--output
aka-o
(you might want to consider using--remote-name
aka-O
here). - Tips for pretty printing
- JSON using
npm
installing thenodejs
packagejson
.pip
forpython
installing thepjson
package.gem
forruby
installing thecolorful_json
gem.- linux using the
yajl-tools
package.
- XML using
- linux using the
libxml2-utils
package - linux using the
tidy
package.
- linux using the
- JSON using
–jeroen
PS: Just discovered someone wrote a Unicode compatible Delphi wrapper for some of the libcurl [WayBack] functionality.
Filed under: *nix, Communications Development, cURL, Delphi, Development, HTTP, https, Internet protocol suite, JavaScript/ECMAScript, JSON, Power User, REST, Scripting, Security, Software Development, TCP, TLS, XML, XML/XSD
