HTML-HTML协议简单解析
在浏览器访问一个地址:
127.0.0.1:7890/html/html.htm //代表访问当地服务器路径下的/html的html.htm文件
客户端发送的请求命令是:(可能是GET/POST/…)
GET /html/html.htm HTTP/1.1
Host: 127.0.0.1:7890
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
(服务器可以用python,c/等等都可实现)
服务器需要回:
2部分:header(规则)+body(数据)
1.给客户端(即给浏览器)回一个 header
“HTTP/1.1 200 OK\r\n”
header的具体格式应该是:
HTTP/1.1 200 OK
Bdpagetype: 1
Bdqid: 0xe87cb317e8023783
Bduserid: 0
Cache-Controt: private
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Cxy-all: baidu+55617f8533383cbe48d5d2b7dc84b7f0
Date: Fri, 20 oct 2017 88:59:55 GMT
Expires: Fri, 20 oct 2017 8e:59:11 GMT
Server: BWS/1.1
Set-Cookie: BOSVRTH=0; patha=/
Set-Cookie: BO_HOHE=0; path=/
Set-Cookie: H_PS_PSSID=1463_21888_17081_2929; path=/;
donaine=baidu. com
Strict-Transport-Security: max-age-172800
Vary: Accept-Encoding
X-Powered-By: HPHP
X-Ua-Compatible: IE=Edge, chrome=1
Transfer-Encoding: chunked
2.解析客户端提示路径的文件数据,并发送给客户端-- 回body
如:发送./html/html.htm文件的数据给客户端
客户端收到后,即可打开页面
代码操作见:Python栏目