Take the 2-minute tour ×

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
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
<title>400 Bad Request</title> </head><body> <h1>Bad Request</h1>
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] Client sent malformed Host header

Can someone please help me with this. What is wrong with the header?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Host should be simple localhost in this case:

GET / HTTP/1.0
Host: localhost
share|improve this answer
Hey Thanks DV13. You saved my day. –  Ankit Nov 22 '11 at 0:16
Sure, no problem! –  DV13 Nov 22 '11 at 0:25
add comment

Your Answer


