Friday, September 29, 2006

HTTP Get Response using Command prompt

Do telnet to the website. Use port 80 (HTTP port) . I recommend this for two reasons -
1. Generally most sites dont keep their telnet port (23) open.
2. If it is open you require login-password to login to the server

For newbies, open command prompt (Start>Run>cmd)
c:\> telnet www.google.co.in 80

Then u will get a blank screen (i.e there is a process waiting for request from the browser (therefore no login screen - shell without prompt) )

Enter either -

GET / HTTP/1.1
Host: www.google.co.in

or

GET http://www.google.co.in HTTP/1.1
Host: www.google.co.in

(Refer http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html for more details)

You get output as (Notice the HTTP Response header) -

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html
Set-Cookie: PREF=ID=768f0ec24c16778c:TM=1159508943:LM=1159508943:S=teTiYAhOOObRT
J0p; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.co.in
Server: GWS/2.1
Transfer-Encoding: chunked
Date: Fri, 29 Sep 2006 05:49:03 GMT

cf1
<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859
-1"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}

.h{font-size:20px}
.q{color:#00c}
--></style>
<script>
<!--
function sf(){document.f.
q.focus();}
// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc
vlink=#551a8b alink=#ff0000 onLoad=sf() topmargin=3 marginheight=3><center><tab
le border=0 cellspacing=0 cellpadding=0 width=100%><tr><td align=right nowrap><f
ont size=-1><a href="/url?sa=p&pref=ig&amp;amp;pval=3&q=http://www.google.co.in/ig%3Fhl%
3Den&sig=__2FXiR2zyqvKLKznVZcY0dUpbPo8=">Personalized Home</a> | <a hr
ef="https://www.google.com/accounts/Login?continue=http://www.google.co.in/&hl=e
n">Sign in</a></font></td></tr><tr height=4><td><img alt="" width=1 height=1></t
d></tr></table><table cellpadding=0 cellspacing=0 border=0><tr><td align=right v
align=bottom><img src=images/hp0.gif width=158 height=78 alt="Google"></td><td v
align=bottom><img src=images/hp1.gif width=50 height=78 alt=""></td><td valign=b
ottom><img src=images/hp2.gif width=68 height=78 alt=""></td></tr><tr><td class=
h align=right valign=top><b></b></td><td valign=top><img src=images/hp3.gif widt
h=50 height=32 alt=""></td><td valign=top class=h><font color=#6f6f6f style=font
-size:16px><b>India</b></font></td></tr></table><br>
<form action=/search name=f>
<table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web<
/b> <a class=q href="/imghp?hl=en&ie=UTF-8&tab=wi">Images
</a> <a class=q href="http://groups.google.co.in/grphp?hl
=en&ie=UTF-8&tab=wg">Groups</a> <a class=q href="http://n
ews.google.co.in/nwshp?hl=en&ie=UTF-8&tab=wn">News</a> <b
><a href="/intl/en/options/" class=q >more »</a></b></font></td></tr>
</table><table cellspacing=0 cellpadding=0><tr><td width=25%> </td><td alig
n=center><input type=hidden name=hl value=en><input type=hidden name=ie value="I
SO-8859-1"><input maxlength=2048 size=55 name=q value="" title="Google Search"><
br><input type=submit value="Google Search" name=btnG><input type=submit value="
I'm Feeling Lucky" name=btnI></td><td valign=top nowrap width=25%><font size=-2>
<a href=/advanced_search?hl=en>Advanced Search</a><br> <a
href=/preferences?hl=en>Preferences</a><br> <a href=/language_tools?
hl=en>Language Tools</a></font></td></tr><tr><td colspan=3 align=center><font si
ze=-1>Search: <input id=all type=radio name=meta value="" checked><label for=all
> the web </label><input id=cty type=radio name=meta value="cr=countryIN" ><labe
l for=cty> pages from India </label></font></td></tr></table></form><br><font si
ze=-1>Google.co.in offered in: <a href="http://www.google.co.in/hi">Hindi</a> <
a href="http://www.google.co.in/bn">Bengali</a> <a href="http://www.google.co.i
n/te">Telugu</a> <a href="http://www.google.co.in/mr">Marathi</a> <a href="htt
p://www.google.co.in/ta">Tamil</a> </font><br><br><br><font size=-1><a href="/in
tl/en/ads/">Advertising Programs</a> - <a href=/intl/en/about.html>About Go
ogle</a> - <a href=/intl/en/jobs/>We're Hiring</a> - <a href=http://www.google.c
om/ncr>Go to Google.com</a></font><p><font size=-2>©2006 Google</font></p><
/center></body></html>

Above example shows a simple trick that you can use to get the http response header. You can get post headers also on similar lines.

2 comments:

Nilanjan Raychaudhuri said...

Thanks a lot for the post. It saved lot of time for me

Unknown said...

This did not work for me on https server. I telnet using port 443 and get the flashing cursor in my telnet window and enter GET /HTTP/1.1 and get nothing, just goes to the next line and flashes.