curl
Fetch a page, see only the headers with curl -I, save it with curl -o — the quickest way to check a server answers.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
curl localhost:8080 -
curl -I localhost:8080 -
curl -s localhost:8080 | grep title -
curl -o page.html localhost:8080 -
head -n 4 page.html -
curl -O localhost:8080/index.html
How it works
curl URL asks a web server for a page and prints what comes back. It is the first thing to try when a site "doesn't work": does anything answer at all?
-I shows only the headers (the status line HTTP/1.1 200 OK says if it worked), -o FILE saves the answer into a file instead of printing it.
Syntax
curl [-I] [-i] [-s] [-o FILE | -O] URL
Options
| Option | What it does |
|---|---|
URL | the address: localhost:8080, http://web-01, https://… |
-I | only the headers |
-i | the headers, then the page |
-s | silent: no progress meter or errors |
-o FILE | save the answer into FILE |
-O | save it under the name at the end of the URL |
Good to know
- "Couldn't connect to server" means nothing listens on that port: is the container running, and did you publish the port with
-p? - This playground is offline: curl reaches your own containers and servers, not the internet.