curl
NetworkFundamentals In real LinuxTransfer 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 FILE | Save to the file FILE |
| -O / --remote-name | Save under the remote file name |
| -s / --silent | No progress bar or error messages |
| -S / --show-error | With -s: still show errors |
| -f / --fail | On HTTP errors (404, 500) print no page and exit non-zero (for scripts) |
| -L / --location | Follow redirects |
| -I / --head | Fetch headers only |
| -i / --include | Include the response headers in the output |
| -v / --verbose | Show the whole request and response (for debugging) |
| -X / --request METHOD | Request method, e.g. POST |
| -H / --header HEADER | Add a header |
| -d / --data DATA | Data to send |
| -F / --form NAME=VALUE | Submit a form, files included: -F "[email protected]" |
| --json DATA | Send JSON (sets Content-Type and uses POST) |
| -u / --user USER:PASSWORD | User name and password (HTTP basic auth) |
| -A / --user-agent NAME | Set the User-Agent |
| -k / --insecure | Do not check the HTTPS certificate (testing only) |
| -C / --continue-at OFFSET | Resume: -C - carries on where it stopped |
| -w / --write-out FORMAT | Print information at the end, e.g. -w "%{http_code}" for the status code |
| -m / --max-time SECONDS | At 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/echoSend 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