这个HTTP请求有什么问题?

问题描述:

我在我的Linux机器上安装了一个Apache,我正在尝试编写一个维护TCP连接以检索网页的HTTP客户端。这个HTTP请求有什么问题?

这样做,我先打开一个套接字为localhost和写入以下头部

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 

然而,阿帕奇给了我一个错误的请求错误,它看起来像这样

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> 

的阿帕奇错误日志说: [Mon Nov 21 15:58:03 2011] [error] [client 127.0.0.1] Client sent malformed Host header

有人可以帮助我这个。标题有什么问题?

主机应该是简单本地主机在这种情况下:

GET/HTTP/1.0 
Host: localhost 
... 
+0

嘿感谢DV13。你拯救了我的一天。 – Ankit

+0

当然,没问题! – DV13