1.HTTP的四种交互
GET:查
POST:改
PUT:增
DELETE:删
一般来说只使用GET/POST
2.HTTP头(分为请求头和响应头)
请求头:
格式如下:
<request
-line
>
<headers >
<blank line >
[ <request -body >]
<headers >
<blank line >
[ <request -body >]
请求行(request line):用来说明请求类型、要访问的资源以及使用的HTTP版本\
头域(header):用来说明服务器要使用的附加信息
空行(blank line):用来隔开头域和请求主体
对于www.baidu.com的GET请求如下所示:
GET
/ HTTP
/
1.
1
Host : www.baidu.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
Host : www.baidu.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
Host : www.baidu.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
Host : www.baidu.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 >]
<headers >
<blank line >
[ <response -body >]
一个HTTP响应的例子:
HTTP
/
1.
1
200 OK
Date : Sat, 31 Dec 2005 23 : 59 : 59 GMT
Content -Type : text /html;charset =ISO - 8859 - 1
Content -Length : 122
<html >
<head >
<title >Wrox Homepage < /title >
< /head >
<body >
< ! -- body goes here -- >
< /body >
< /html >
Date : Sat, 31 Dec 2005 23 : 59 : 59 GMT
Content -Type : text /html;charset =ISO - 8859 - 1
Content -Length : 122
<html >
<head >
<title >Wrox Homepage < /title >
< /head >
<body >
< ! -- body goes here -- >
< /body >
< /html >