cURL HTTP GET request command examples


cURL is the most widely used command on the terminal/console to test an HTTP GET request payload. It is very simple to use is comes pre-installed on Windows Command Line and macOS terminal.

cURL HTTP GET request Syntax:

curl THE-HTTP-GET-URL
Example:
curl http://code2care.org/testing-http-get-with-curl-command
Output on Windows Command Prompt:
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>This page was viewed using cURL command</title>
    </head>
    <body>
        <h1>Hello World! cUrl Http Get</h1>
    </body>
</html>
Example macOs or Linux Terminal:
$ curl google.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   219  100   219    0     0   2009      0 --:--:-- --:--:-- --:--:--  2009
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"&gt;
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

As you can see in the examples this is the most simplest cURL command to fetch the content of an HTTP URL, it will print out the whole HTML source code of the URL in the console as output.

cURL HTTP GET request with Response Headers:

If you are interesting in knowing the HTTP response headers as well you can make use of argument -i (include) to print it, as you can see below the headers are printed before the HTML payload.

$ curl -i google.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   219  100   219    0     0   1063      0 --:--:-- --:--:-- --:--:--  1068

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sat, 01 Aug 2020 11:43:19 GMT
Expires: Mon, 31 Aug 2020 11:43:19 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>