HTTP协议
请求头都是以字符串的方式发送和解析的
客户端发送请求(request):
GET / HTTP/1.1 # 格式:请求方式|路径|HTTP版本
Host: www.baidu.com
Connection: keep-alive
Cache-Control: max-age=0 # 缓存的最大周期
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36 # 浏览器的信息
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br # 压缩格式
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4 # 编码格式
Cookie: BAIDUID=7874FBE40A36835D1F29FDA453E70193:FG=1; PSTM=1498464660; BIDUPSID=D3F7611A19AE1C18A9B66329F1A9C6F9; BDUSS=zE5N0x2TUZITHV-dVpyMExnU0l3eW5BT3ppUjJvdEV2S2tTbElFdDF-Vk5lSTVaTVFBQUFBJCQAAAAAAAAAAAEAAABaMNpIQ2xhcm9qYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE3rZllN62ZZY; MCITY=-315%3A; __cfduid=da3186a4d0f6ec740db5951f70cf4b8a41504752275; __cacheid=1506315722745625-3027136218; pgv_pvi=5447443456; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BD_CK_SAM=1; PSINO=3; BD_HOME=1; H_PS_PSSID=1458_21111_24022_20928; BD_UPN=123353; sugstore=1
- 1
1.起始行
2.请求头
3.请求体
content_length:128
4.HTTP请求方式
GET 获取数据,放到请求头里,没有请求体,用?号传递数据
POST 修改数据,可以放在请求头里,也可以放在请求体里
PUT 保存数据
DELETE 删除数据
OPTION 询问服务器的支持特性
HEAD 返回报文头
服务器响应(response)
HTTP/1.1 200 OK #格式 HTTP版本|request执行是否成功的状态吗|
Bdpagetype: 2
Bdqid: 0x80ec36bf000098e8
Bduserid: 1222258778
Cache-Control: private
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html;charset=utf-8
Date: Mon, 23 Oct 2017 05:33:29 GMT
Expires: Mon, 23 Oct 2017 05:33:29 GMT
Server: BWS/1.1
Set-Cookie: BDSVRTM=275; path=/
Set-Cookie: BD_HOME=1; path=/
Set-Cookie: H_PS_PSSID=1458_21111_24022_20928; path=/; domain=.baidu.com
Strict-Transport-Security: max-age=172800
X-Ua-Compatible: IE=Edge,chrome=1
Transfer-Encoding: chunked
- 1
1.起始行
2响应头
3.响应体
URL
URL(location):通过位置寻找
URN (Name):通过名字寻找
URI (Identifier):是URL和URN的合称
URL的组成:
方案|主机|[端口]|路径|查询|片段
http://www.baidu.com:80/index.html?q=”百度”#hook
方案:生命了访问的协议是什么,用冒号隔开,比如HTTP:
主机与端口:主机前用”//”斜杠,主机和端口之间用”:”隔开
路径:表明资源在服务器的位置
查询:向数据库发送请求,与之前的用”?”隔开,查询参数之间用”&”隔开
参数:发送的参数请求,参数之间用”;”隔开
片段:定位到网页的某个部分,用#隔开
http://write.blog.csdn.net/mdeditor#!postId=78318121
参考文献:
HTTP权威指南