Useful cURL commands

Basic Requests

Get request

$ curl

Post request

$ curl -X POST

Put request

$ curl -X PUT -d ""

Delete request

$ curl -X DELETE

Post request with parameters

$ curl -d "username=marko&password=secret"

The above post type is application/x-www-form-urlencoded, for multipart post you can use:

$ curl -L username=marko -L password=secret

You can use -v to see output including request + response headers, or -I to fetch the HTTP-header only.

File Handling

Download a Single File

$ curl http://localhost/file.txt > file.txt

Fetch Multiple Files at a time

$ curl -O url1 -O url2

Continue/Resume a Previous Download

$ curl -C - -O http://localhost/file.txt

Limit the Rate of Data Transfer
The command bellow is limiting the data transfer to 1000 Bytes/second.

$ curl --limit-rate 1000B -O http://localhost/file.txt

Download Files from FTP server

$ curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/xss.php


Follow HTTP Location Headers with -L option

$ curl -L http://localhost

Set Request Headers

$ curl -H "Accept: application/json" \
     -H "Authorization: OAuth 2c3455d1aeffc" \

Send a Request Body

$ curl -X PUT \
     -H 'Content-Type: application/json' \
     -d '{"firstName":"Marko", "lastName":"Gajst"}' \

Use a File as a Request Body

$ curl -X PUT \
     -H 'Content-Type: application/json' \
     -d @example.json \

This is archived version of blog, preventing broken links. This version will stay online indefinitely.