This works on my system (Just brings back 128 bytes HTTP header). (Note
the extra ‘\n’…
That’s one too many \n’s now. There’s one already at the end of Host:
www.google.com\n, so you only need one more to give the blank line.
But actually, to comply with RFCs, you need to send \r\n at the end of
mySock = TCPSocket::new(“www.google.com”, 80)
mySock.write(“GET / HTTP/1.1\r\n”)
data = mySock.recv(128)
Quite a few webservers gracefully accept \n, but there are also plenty
strict ones which don’t - including Mongrel I believe.
\r\n - yup I remember that being necessary now in other programs - I
guess (as you say) ‘\n\n’ just sometimes works…
//That’s one too many \n’s now//
But note, the program did really hang on my system (ruby 1.8.6
(2007-09-24 patchlevel 111) [i386-mswin32]) until I introduced that
extra ‘\n’ and then it did really work.
Possibly (I haven’t tried this…) the \n\n is google’s webserver just
thinking ‘oh you mean \r\n really’…(as you pointed out essentially).