Using echo, netcat(nc) and tr to create an HTTP connection
Fortunately for debugging HTTP connections, there is a very simple way of generating one from command line when
elinks or
lynx are not available.
For this we need the most basic http command and header: GET/POST and Host.
Code:
# echo 'GET / HTTP/1.1 Host: www.mysite.ro'
GET / HTTP/1.1 Host: www.mysite.ro
but the above output is not valid for sending it to a web server. We need some new lines added to it:
Code:
# echo 'GET / HTTP/1.1BHost: www.mysite.roB' | tr "B" "\n"
GET / HTTP/1.1
Host: www.mysite.ro
Now I'll take the above output (where
tr replaced the B (uppercase B) with a new line) and inject it into a webserver using netcat (nc):
Code:
# echo 'GET / HTTP/1.1BHost: www.mysite.roBB' | tr "B" "\n" | nc localhost 80
HTTP/1.1 200 OK
Date: Thu, 04 Mar 2010 08:56:15 GMT
Server: Apache/2.2.13 (Unix) DAV/2 mod_ssl/2.2.13 OpenSSL/0.9.8k
Set-Cookie: 0b1edb316356a304958c8070b6cd7673=8c2a000573ba9f66fc2379fbcf4b3fda; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Mon, 1 Jan 2001 00:00:00 GMT
Last-Modified: Thu, 04 Mar 2010 08:56:15 GMT
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Connection: close
...rest of the output is ommited...
What appears below my command is the webserver's output to the http GET command and the HOST header.
P.S.: In this case,
www.mysite.ro is not hosted and the webserver serves the default vhost.