In the previous article we learned about the -o
or --output
flag (or option). Now we will explore the -v
flag which stand for --verbose
.
If we want to see all the verbose details of our request and response, we need to pass in the -v
flag. The particular option takes no arguments. It's like a boolean, it's either on or off.
Now we'll see what's going on "under the hood" as the manual states. Try the following command in your terminal.
$ curl -v http://www.example.com
The top what what was printed to your STDOUT should look something like this.
* Trying 2606:2800:220:1:248:1893:25c8:1946:80...
* Connected to www.example.com (2606:2800:220:1:248:1893:25c8:1946) port 80 (#0)
> GET / HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.85.0
> Accept: */*
The lines that begin with an asterisk are helpful messages curl is telling us. The lines that begin with an angle bracket are the actual HTTP request/response details.
The Request
These are the details of the HTTP request you just made.
Let's break it down line by line.
You attempted to connect to the IP address 2606:2800... This is the full Internet Protocol Version 6 address which we referred to by the domain name
example.com
Next we see that we successfully connected at port #80
This particular request method was a 'GET' request via the HTTP version 1 protocol.
The host domain name we specified in our command
An HTTP
header
we sent, being ourUser-Agent
which is of course curl. 7.85.0 is my specific version. Yours may be different. You can see your version of curl by typing$ curl -V
.Lastly, another HTTP
header
we sent, being theAccept
header which specifies what type of content (MIME type) we are willing to accept in response. It this case, everything!*/*
The Response
Here are the details of the response.
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Age: 266872
< Cache-Control: max-age=604800
< Content-Type: text/html; charset=UTF-8
< Date: Sat, 04 Mar 2023 16:21:04 GMT
< Etag: "3147526947+ident"
< Expires: Sat, 11 Mar 2023 16:21:04 GMT
< Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
< Server: ECS (cha/8094)
< Vary: Accept-Encoding
< X-Cache: HIT
< Content-Length: 1256
* Mark bundle as not supporting multiuse
. This message appears because in this case we are using HTTP version 1 which does not support multiplexing or multiuse. HTTP 2 does.The version of HTTP and the response status code. In this case, it's successful. 200! OK!
The rest of the lines contain all the response headers sent back from example.com. If you're interested, you can find information about all HTTP headers at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers.
How to look up specific curl options
One of the difficulties you will undoubtedly face when leaning curl is finding the right option from the manual. Let's say you want to learn about the --verbose
or --output
flags but you don't feel like scrolling through the manual to find them. You can search the manual with grep
.
We are going to "pipe" the output of the manual into the grep
utility. Grep is basically a searching tool. Try this command and then I'll explain what it's doing.
$ man curl | grep -B 5 -A 25 -e '-v, --verbose'
First, we used the vertical bar character or "pipe" to pipe the output of man curl
into the grep
command.
Grep takes an expression to search for. That's why we passed the -e
flag with the argument -v, --verbose
. We are searching for that expression in the curl manual. Grep will return all the places where that specific string occurs. There should be only one.
However, before the -e
flag, we passed in two other flags and arguments: -B
with argument 5
and -A
with argument 25
. That means we want to print out 5 lines before
the expression occurs and 25 lines after
the expressing occurs.
Use can use this piping trick to search for specific commands in the curl manual.
Ready to go more in depth? Read A Beginner's Guide to Curl: Part 4.
Top comments (0)