0
我在我的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
有人可以幫助我這個。標題有什麼問題?
嘿感謝DV13。你拯救了我的一天。 – Ankit
當然,沒問題! – DV13