0X0
HTTP(HyperText Transfer Protocol)超文本传输协议,是web服务器到web浏览器之间传输的通信规则。
0x01
HTTP协议目前最新版本是1.1,HTTP是一种无状态的协议,只能由客户端发起,服务器端不能主动向客户端发送数据。
应答模型:
Request请求
客户端 =============》服务端
《============
Response响应
0x02 HTTP请求
包括三个部分:1、请求行; 2、请求头; 3、请求正文。
实例:
GET /notification/notification_count/ HTTP/1.1 请求行
Host: mp.xxxxxx.com 请求头
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Firefox/52.0 (User-Agent代表浏览器标识。)
Accept: application/json, text/javascript, */*; q=0.01 正文
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://mp.toutiao.com/profile_v2/publish
X-Requested-With: XMLHttpRequest
图例brupsuite:
使用python socket测试http响应的效果:
import socket
t_host ="www.toutiao.com"
t_port = 80
client = socket.socket()
client.connect((t_host,t_port))
client.send("GET / HTTP/1.1\r\nHost:toutiao.com\r\n\r\n")
response = client.recv(4096)
print response
HTTP/1.1 502 Bad Gateway //响应行 HTTP的版, 状态码 502,消息是Bad Gateway
Server: Tengine //响应头 由服务器向客户端发送
Content-Length: 0
Connection: keep-alive
Via: cache5.cn218[0,502-257,M], cache4.cn218[14,1,502001]
X-Swift-Error: dns domain not exist
Timing-Allow-Origin: *
EagleId: 790e0d0415057759521686693e
........由于response获取的字节有限下面是响应正文,是服务器向客户端发送的HTML数据。
EOF:下一遍我将讲述HTTP的请求方法,请期待。