Back to the command reference

curl

NetworkFundamentals In real Linux

Transfer data with URLs; great for HTTP APIs

Name: curl = client URL (also read "see URL")

This command needs a real Linux system; you can practise it in real Linux mode.

Description

curl transfers data with URLs over dozens of protocols, including HTTP, HTTPS and FTP. It writes the response to standard output by default and can set methods and headers, send data and handle cookies and authentication; one of the most used tools for testing web APIs.

Syntax

curl [OPTION]... URL...

Common options

-o / --output FILESave to the file FILE
-O / --remote-nameSave under the remote file name
-s / --silentNo progress bar or error messages
-S / --show-errorWith -s: still show errors
-f / --failOn HTTP errors (404, 500) print no page and exit non-zero (for scripts)
-L / --locationFollow redirects
-I / --headFetch headers only
-i / --includeInclude the response headers in the output
-v / --verboseShow the whole request and response (for debugging)
-X / --request METHODRequest method, e.g. POST
-H / --header HEADERAdd a header
-d / --data DATAData to send
-F / --form NAME=VALUESubmit a form, files included: -F "[email protected]"
--json DATASend JSON (sets Content-Type and uses POST)
-u / --user USER:PASSWORDUser name and password (HTTP basic auth)
-A / --user-agent NAMESet the User-Agent
-k / --insecureDo not check the HTTPS certificate (testing only)
-C / --continue-at OFFSETResume: -C - carries on where it stopped
-w / --write-out FORMATPrint information at the end, e.g. -w "%{http_code}" for the status code
-m / --max-time SECONDSAt most this many seconds for the whole request

Examples

  • $ curl http://web01/

    Fetch web01’s home page

    Explain
  • $ curl -I http://web01/

    Status and headers only

    Explain
  • $ curl -X POST -H "Content-Type: application/json" -d '{"name":"alice"}' http://web01/cgi-bin/echo

    Send JSON with POST; web01 answers with what it got

    Explain
  • $ curl -O http://web01/files/report.txt

    Download a file under its own name

    Explain

Related