概念:Hyper Text Transfer Protocol 超文本传输协议
定义了客户端与服务器通信时,发送数据的格式
特点:
1.基于TCP/IP协议
2.默认端口号:80
3.基于请求/响应模型:一次请求对应一次响应
4.无状态的:每次请求之间相互独立,不能交互数据
请求消息的数据格式:1.请求行请求方式 请求url 请求协议/版本GET /login.html HTTP/1.1请求方式:HTTP协议有7中请求方式,常用的有两种GET: 请求参数在请求行中,在url后请求的URL的长度是有限制的不太安全POST: 请求参数在请求体中请求的URL没有长度限制相对安全2.请求头常见请求头信息:1.User-Agent:浏览器告诉服务器它的版本信息,在服务器端获取该信息,解决浏览器的兼容问题2.Referer:http://localhost:8080/login.html告诉服务器我从哪里来:1.防盗链2.统计工作例子:Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3Accept-Encoding: gzip, deflate, brAccept-Language: zh-CN,zh;q=0.9Cache-Control: max-age=0Connection: keep-aliveContent-Length: 12Content-Type: application/x-www-form-urlencodedCookie: Idea-b8e60331=9a75d97e-7411-40c1-b780-553a49d84a22; Pycharm-5defaf00=266be6fb-5264-46e4-85f6-0832a2389f0c; JSESSIONID=D5F0F4F188FCB5FC86271727538FCB51Host: localhost:8080Origin: http://localhost:8080Referer: http://localhost:8080/login.htmlSec-Fetch-Mode: navigateSec-Fetch-Site: same-originSec-Fetch-User: ?1Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.363.请求空行空行,用来分隔POST的请求头和请求体4.请求体(正文)GET没有请求体,POST有请求体username=qqq例子:GET /login.html HTTP/1.1Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3Accept-Encoding: gzip, deflate, brAccept-Language: zh-CN,zh;q=0.9Cache-Control: max-age=0Connection: keep-aliveContent-Length: 12Content-Type: application/x-www-form-urlencodedCookie: Idea-b8e60331=9a75d97e-7411-40c1-b780-553a49d84a22; Pycharm-5defaf00=266be6fb-5264-46e4-85f6-0832a2389f0c; JSESSIONID=D5F0F4F188FCB5FC86271727538FCB51Host: localhost:8080Origin: http://localhost:8080Referer: http://localhost:8080/login.htmlSec-Fetch-Mode: navigateSec-Fetch-Site: same-originSec-Fetch-User: ?1Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36username=qqq