The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,731 other followers

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"

source: How to send a header using a HTTP request through a curl call? – Stack Overflow [WayBack]

There are some more examples at 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).
    • 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.
  • 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 the nodejs package json.
      • pip for python installing the pjson package.
      • gem for ruby installing the colorful_json gem.
      • linux using the yajl-tools package.
    • XML using
      • linux using the libxml2-utils package
      • linux using the tidy package.


PS: Just discovered someone wrote a Unicode compatible Delphi wrapper for some of the libcurl [WayBack] functionality.

One Response to “Sending various HTTP request kinds using curl”

  1. You have also a TCurlHTTP class defined in which works under Windows, but also under Linux, OSX and BSD via FPC.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: