curl Notes


Client URL (cURL is a handy tool for transferring data specified with URLs. I mostly use it for pulling down files when I’m working on a server remotely. I also use it to check servers I’m configuring or test APIs.

Basic cURL Usage

File Downloads

Giving curl the URL of a webpage will display it in your console window.


Use -o to specify a filename to save the output to a file.

curl -o out.html

Using the -O option will download a file with its original name

curl -O

Download a script and run with bash uwing the pipe |. ( -o- redirects out put to stdout, which is the default. So it’s not necessary here)

curl -o- | bash

Sometimes a download gets interrupted. When this happens, you can resume a download with the -C option. ( -L here handles redirects )

curl -L -O -C -

The -u options lets you specify a username. cURL will prompt you for the password

curl -u username

You can also specify a password by following the username with a colon and the password ( This is not recommended as the command can be viewed while its running )

curl -u username:password

Testing With cURL

Getting information on a server

Use -v to get verbose output about the connection. This can be helpful when debugging a problem.

 curl -v

Sometimes it’s helpful to see the headers returned from the server. Use -I or -i to view Headers.

curl -i  # Headers with Body
curl -I  # Headers Only

-H is used to set headers. This can be use to specify a website If your sever is handling multiple websites.

curl -H 'Host:'
curl -H 'Host:'

API Testing

When I’m testing APIs I don’t really want to see the progress info. I use -s to hide it

curl -s

I often use test servers with self signed certificates. Use -k to bypass SSL checks

curl -k

I use -w to view HTTP codes when I test APIs. The following command just shows the http code by redirecting stdout to /dev/null

curl -o /dev/null -s -w "%{http_code}\n"

My APIs tend to use JWT for authentication. I specify the bearer token in a header with -H.

curl -s -w "%{http_code}\n" -H 'Accept: application/json' \
    -H "Authorization: Bearer ${TOK}"  \ \
    -H "Content-Type: application/x-www-form-urlencoded"  \
    -d "title=The Title&summary=blah blah blah&body=blah blah blah blah blah&publish=true"

This assumes ${TOK} has been set to the bearer token value.


The following example uses -H to set the Content-Type as URL encoded.

curl -s -w "%{http_code}\n" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "title=The Title&summary=Article Summary Here&body=Lorem ipsum dolor sit amet, consectetur adipiscing elit,&publish=false"

This specifies the Content-Type as JSON.

curl  -s -w "%{http_code}\n"  -H 'Accept: application/json' \
   -X POST  \
   -H "Content-Type: application/json"  \
   -d '{"title":"The Title","summary":"Article Summary Here","body":"Lorem ipsum dolor sit amet","publish":true,"keywords":["text"]}'

-X can be used to set the HTTP Method. It’s not strictly necesary, because curl can infer the method from other options. -d implies a POST, so specifying -X POST is not necessary here


Using -T uploads a file as a PUT operation

curl -H "Authorization: Bearer ${TOK}" -T /path/to/local/file.txt

You can also use -X PUT to override -d and specify the data in the command instead of using a file.

curl -s -w "%{http_code}\n"   \ 
    -H 'Accept: application/json'  \ 
    -H "Authorization: Bearer ${TOK}"  \ 
    -H "Content-Type: application/x-www-form-urlencoded"  \ 
    -d "name=flat color" -X PUT"

Send a delete with -X DELETE

curl -s -w "%{http_code}\n"  \
    -H 'Accept: application/json' \
    -H "Authorization: Bearer ${TOK}" \
    -X DELETE"

Use -c, --cookie-jar and -b, --cookie to manage cookies.

The following command saves HTTP cookies to a file called cookie.jar

curl -o -  -s -w "%{http_code}\n" \
    -X POST \
    -H "Content-Type: application/x-www-form-urlencoded"\
    -d "username=someuser&password=somepass" \
    --cookie-jar cookie.jar

The following uses the cookie.jar file to send the cookies with the HTTP request.

curl -o -  -s -w "%{http_code}\n" \
    -X POST  \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "param1=5043&param2&abbybabble" \
    -b cookie.jar

About Me

Greg Gallardo

I'm a software developer and sys-admin in Iowa. I use C++, C#, Java, Swift, Python, JavaScript and TypeScript in various projects. I also maintain Windows and Linux systems on-premise and in the cloud ( Linode, AWS, and Azure )




About you

IP Address:

User Agent: CCBot/2.0 (

Language: en-US,en;q=0.5

Latest Posts

Iowa City Weather


-- ˚F / 61 ˚F


71 ˚F / 54 ˚F


64 ˚F / 46 ˚F


76 ˚F / 54 ˚F


76 ˚F / 56 ˚F


72 ˚F / 51 ˚F


67 ˚F / 47 ˚F