I have a Apache installed on my Linux machine and I am trying to write a HTTP client that maintains a TCP connection to retrieve a web-page.
To do that I, first open a socket to localhost and write the following head
GET / HTTP/1.0
Host: http://localhost:80
User-Agent: My-User-Agent 1.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control: no-cache
Accept-Language: en;q=0.7,en-us;q=0.3
Connection: close
However, apache gives me a Bad Request error, which looks like this
HTTP/1.1 400 Bad Request
Date: Mon, 21 Nov 2011 23:58:03 GMT
Server: Apache/2.2.20 (Ubuntu)
Vary: Accept-Encoding
Content-Length: 311
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title> </head><body> <h1>Bad Request</h1>
<p>Your browser sent a request that this server could not
understand.<br /> </p> <hr> <address>Apache/2.2.20 (Ubuntu) Server at
http://localhost:80 Port 80</address> </body></html>
The apache error log says this:
[Mon Nov 21 15:58:03 2011] [error] [client 127.0.0.1] Client sent malformed Host header
Can someone please help me with this. What is wrong with the header?
Host should be simple localhost in this case: