HTTP协议----(1)手工发送HTTP请求报文

例:向 http://www.baidu.com 发送HTTP请求报文信息

 

1.CMD中输入:
  telnet www.baidu.com 80

 

2.输入请求报文:然后两次回车换行。  【可以在FireFox下查看这些请求/响应的报文信息】
GET /index.php HTTP/1.1
Host: www.baidu.com:8088
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: JSESSIONID=C6C21E45C94452A8352A94267688B0F6
Cache-Control: max-age=0

 

精简请求报文:然后两次回车换行
HEAD / HTTP/1.0


3.响应报文头:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Content-Length: 963
Date: Mon, 28 Jun 2010 14:57:10 GMT

 

4.发送POST请求:(参数行与header行之间要有一空行,最后要有2个回车换行。)

 

POST http://192.168.87.45:8088/WebDemo/LoginServlet HTTP/1.1
Host: 192.168.87.45:8088
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15
Accept: */*
Accept-Language: en-US,zh-cn;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://192.168.87.45:8088/WebDemo/test.jsp
Content-Length: 29
Cookie: JSESSIONID=AEC5F66EAF600AA89DF721FECFCB1B76
Pragma: no-cache
Cache-Control: no-cache

username=nami&password=123456
 

 

 

 

 

posted on 2010-06-29 00:00  TroyZ  阅读(2724)  评论(0编辑  收藏  举报