Tuesday 8 September 2009

Testing HTTP using Telnet

While this is commonplace knowledge, I find myself googling for it every time I need to test HTTP connectivity and responses with telnet. Telnet provides a quick and dirty means to put back data over HTTP and to test the response headers.

Firstly, fire up telnet with the hostname and port for the HTTP connection:
telnet www.somesite.com 80
If it can connect to the server, then you will be presented with:

Trying www.somesite.com...
Connected to www.somesite.com.
Escape character is '^]'.

Now type the following to request index.html over HTTP:

GET /index.html HTTP/1.1
host: www.somesite.com

This will then return the header information, followed by the actual data.

1 comment:

rasputnik said...

Do yourself a big favour and learn to use curl.

It's very rare to find a http webapp that doesn't need cookie support etc. and curl is a total doddle to it

curl http://foo.com/ is only a couple more characters than 'telnet foo.com 80', and you don't have to bother with manually typing headers :)