HTTP 中GET和POST/及常用的状态码
//Get 请求
GET/HTTP/1.1 //表明是GET请求,下一个/表明请求的是域名的根目录,最后的部分说明的是版本
Host: www.bookbook.com //Host首部指明请求的目的地,加上上一行的/,完整的请求地址是:www.wrox.com?aa="bbb"/
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1 //这一行的首部是用户代理
Connection: Keep-Alive//最后一行的首部是Connection,通常都设为Keep-Alive
//就算没有请求主体这里也要有一个空行
//考虑这样的请求:http://www.bookbook.com/books
GET /books/ HTTP/1.1 //注意只有第一行变了
Host: www.wrox.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1
Connection: Keep-Alive
//GET传参
URL?name1=value1&name2=value2&..&nameN=valueN
GET /books/?name=Professional%20Ajax HTTP/1.1 //空格转变为20%
Host: www.bookbook.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1
Connection: Keep-Alive
//POST
POST / HTTP/1.1 //首部是POST
Host: www.bookbook.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1
Content-Type: application/x-www-form-urlencoded //说明如何编码
Content-Length: 40 //说明请求主体的长度
Connection: Keep-Alive
name=Professional%20Ajax&publisher=Wiley //请求主体
//HTTP响应
//格式如下
<status-line>
<headers>
<blank line>
[<response-body>]
HTTP/1.1 200 OK //200是HTTP状态码,以后我们会在Ajax中用到状态码
Date: Sat, 31 Dec 2005 23:59:59 GMT //Date首部
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 122
<html>
<head>
<title>Wrox Homepage</title>
</head>
<body>
<!-- body goes here -->
</body>
</html>
//常用的状态码:
200 (OK): The resource was found and all is well.
304 (NOT MODIFIED): The resource has not been modified since the last request. This is used most often for browser cache mechanisms.
401 (UNAUTHORIZED): The client is not authorized to access the resource. Often, this will cause the browser to ask for a user name and password to log in to the server.
403 (FORBIDDEN): The client failed to gain authorization. This typically happens if you fail to log in with a correct user name and password after a 401.
404 (NOT FOUND): The resource does not exist at the given location.