Check connectivity with curl
In this step, you'll use the curl
command to check connectivity to a web server and retrieve content. curl
is a versatile command-line tool for transferring data with URLs. It supports various protocols, including HTTP, HTTPS, FTP, and more.
Open your terminal if it's not already open.
Let's use curl
to fetch the content of a simple webpage, like example.com
. Type the following command and press Enter:
curl example.com
You will see the HTML content of the example.com
webpage printed directly in your terminal.
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
This shows that your computer was able to connect to example.com
and retrieve its content.
curl
is a powerful tool for testing web connectivity, debugging web services, and downloading files.
You can also use curl
with the -I
option to fetch only the HTTP headers, which is useful for checking the status of a webpage without downloading the entire content:
curl -I example.com
The output will show the response headers:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Etag: "..."
Expires: ...
Last-Modified: ...
Server: ECS (sg2/2A3E)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270
Date: ...
Connection: close
A HTTP/1.1 200 OK
status indicates a successful connection.
curl
is an essential tool for anyone working with web technologies.
Click Continue to complete this lab.