How to access web page via terminal?

My question is, what if I don’t have Chrome/Firefox on? How can I do the equivalent test via the terminal? I tried ping x.x.x.x/directory/index.php but it doesn’t work that way.

Using ping would never work. All ping does is send/receive ICMP packets from a network address. So in your example, the only thing you could actually “ping” is ping x.x.x.x with the remainder of the URL (/directory/index.php) just choking ping as it attempts to resolve the whole URL as if it were a hostname. The error would be something like:

ping: cannot resolve x.x.x.x/directory/index.php: Unknown host

But for the specific type of web server testing/debugging you are looking for, I usually use curl but specifically I use curl -I -L which will throw back just basic response headers and follow any location redirects the server might have in place; the -I flag tells curl to just show the header and -L flag tells curl to follow any server redirects it encounters.

For example, if I run this curl -I -L command on google.com:

curl -I -L google.com

I get the following response headers:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Mon, 24 Aug 2015 02:16:32 GMT
Expires: Wed, 23 Sep 2015 02:16:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

HTTP/1.1 200 OK
Date: Mon, 24 Aug 2015 02:16:32 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: PREF=ID=1111111111111111:FF=0:TM=1440382592:LM=1440382592:V=1:S=5ToXkoBHyK2BAjyf; expires=Thu, 31-Dec-2015 16:02:17 GMT; path=/; domain=.google.com
Set-Cookie: NID=70=VKM1D8HeCMlye1YjMDYSqPlyIpPHKkitAor--wiqYznamENfNig69ZBW5oBgIR7wOFzVaUB6i4WKj-tqa2WcqbOCeVTc0hB4xQWQzBxpNazPp_20dBiU4in0wIop8mhz; expires=Tue, 23-Feb-2016 02:16:32 GMT; path=/; domain=.google.com; HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding

Note there are two headers returned:

  • HTTP/1.1 301 Moved Permanently
  • HTTP/1.1 200 OK

This is useful not just for Apache server testing but also useful for debugging mod_rewrite rewrite rules and such.

This curl -I -L method is far more useful and efficient than using a visual browser like Chrome or Firefox since those programs are designed to optimize browsing speed by caching content. Which means you can make an adjustment to your Apache server one second, but the visual browser won’t necessarily show the change right away unless you clear the cache or force the page to reload a few times. The curl -I -L shows you exactly what the server at that moment is doing in response to your request which is exactly what you want/need when debugging server configs.


The command you want is either curl or wget (depending on your personal preferences). These commands make a HTTP request to the server. They're not great for simulating the load of an entire page (they don't, by default, load the assets referenced by the HTML page, and they can't execute javascript or interact with the page at all), but it doesn't sound like you're after anything that advanced. So, curl or wget will almost certainly work fine for you.


@womble is right. However, if you don't have curl or wget, you can use telnet:

telnet x.x.x.x 80
GET /directory/index.php HTTP/1.1
Host: x.x.x.x

Then hit Enter one more time (for the end of headers) and you’ll get the raw HTML. You may have to hit Ctrl+D (Unix) or Ctrl+Z (Windows) to exit if the server uses keepalive.


You may want to use a text based browser. This option will let you traverse the web page and test more of its components. Things like forms for example, since it is a full-fledged browser.

Use lynx, or its younger brother links, or elinks.


You can issue a GET request with OpenSSL:

openssl s_client -quiet -connect cdn.sstatic.net:443 <<eof
GET /stackexchange/js/universal-login.js HTTP/1.1
Connection: close
Host: cdn.sstatic.net

eof

Note that you can also use "HTTP/2", but be careful because some servers (e.g. github.com) do not support it.