cURL command line utility

curl recipes

curl logo

Determine HTTP status (200, 404, etc.) with --write-out '%{http_code}'

health-probe.sh
#!/bin/bash

function httpStatus { echo "$( curl --silent --output /dev/null --write-out '%{http_code}' $1 )" ; }

echo "Azure: $( httpStatus "https://portal.azure.com/" )"

results in Azure: 200.

Send some XML via POST to a URL

Read body to upload from STDIN (via --data @-)

Read body to upload from file

Tracing your cURL calls with Fiddler

When I want to completely see the traffic originating from my cURL instance, I use Fiddler (a Windows-based HTTP(s)-proxy GUI). Fiddler can be configured to decrypt TLS (https://) traffic, but that means that the server certificate for cURL will be untrusted. The following args instruct cURL to use a local (untrusted) HTTPs-proxy:

Tracing a cURL interaction in Fiddler

Extract both custom HTTP header values and the body from a request

The following script uses cURL to fetch a web page, and then extracts both an HTTP from the response headers, as well as the body.

Last updated