服务器发回 HTTP/1.1 400 Bad Request
linux下,用C写了一个SOCKET向服务器发送了一个HTTP的请求,(static const char* request = "GET /index.html HTTP/1.1\r\n\r\n";)这个只是试验,结果服务器发回的
HTTP/1.1 400 Bad Request
Date: Wed, 21 Aug 2013 08:59:32 GMT
Server: Apache/2.2.24 (Unix)
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
后面还有一个
Your browser sent a request that this server could not understand
这个不正常啊,求大神支招,新人拜谢!!
------解决方案--------------------用网页访问,用wireshark抓包,再安装包内容填写。
------解决方案--------------------带上Host再试一下.
------解决方案--------------------这个应该是GET的格式问题吧,我用wireshark抓访问百度的包,一个GET包有挺多行内容的:
GET / HTTP/1.1\r\n
Host: www.baidu.com\r\n
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n
Accept-Encoding: gzip, deflate\r\n
Cookie: BAIDUID=A21FE77A3E5A4A8B26A82120C14E891B:FG=1; CNZZDATA30081939=cnzz_eid%3D941235294-1376885338-http%253A%252F%252Fwww.baidu.com%26ntime%3D1376885338%26cnzz_a%3D0%26retime%3D1376885338015%26sin%3D%26ltime%3D1376885338015%26rtime%3D0; BDREFER=%7Burl%3A%22http%3A//mil.news.baidu.com/%22%2Cword%3A%22%22%7D; H_PS_PSSID=3157_2777_1429_3139_2785_2981_3092_3108_2701\r\n
Connection: keep-alive\r\n\r\n
我把这个内容发过去,成功收到回复:
HTTP/1.1 200 OK
Date: Thu, 22 Aug 2013 02:56:52 GMT
Server: BWS/1.0
Content-Length: 4491
Content-Type: text/html;charset=utf-8
Cache-Control: private
BDPAGETYPE: 1
BDUSERID: 0
BDQID: 0xac102fc8007bef3a
Set-Cookie: BDSVRTM=2; path=/
Set-Cookie: H_PS_PSSID=3157_2777_1429_3139_2785_2981_3092_3108_2701; path=/; domain=.baidu.com
Expires: Thu, 22 Aug 2013 02:56:52 GMT