You have the right idea, but you are not sending an HTTP request. Submit:
GET / HTTP/1.1\r\nHost: <hostname\r\n\r\n
It follows the format
[METHOD] [PATH] HTTP / 1.1 [CRLF]
Host: [HOSTNAME] [CRLF]
OTHER: HEADERS [CRLF]
[CRLF]
You should get an answer that follows a similar format: header, blank line and data. Read more about the HTTP protocol.
EDIT Perhaps this will help to understand the syntax of the HTTP request. It's pretty simple, and just good to know overall. Open a terminal and use netcat (preferably) or telnet . netcat google.com 80 or telnet google.com 80 . A type:
GET / HTTP / 1.1 [ENTER]
Host: google.com [ENTER]
[ENTER]
I get a response (after the second return):
HTTP / 1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text / html; charset = utf-8
Date: Thu, 09 Dec 2010 00:03:39 GMT
Expires: Sat, 08 Jan 2011 00:03:39 GMT
Cache-Control: public, max-age = 2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode = block
<HTML & <HEAD> <meta http-equiv = "content-type" content = "text / html; charset = utf-8">
<TITLE> 301 Moved </TITLE> </HEAD> <BODY>
<H1> 301 Moved </H1>
The document has moved
<A HREF="http://www.google.com/"> here </A>.
</BODY> </HTML>
As soon as you feel the syntax of the request, just write it on the socket, then read the lines until the server closes, as you do.
source share