1.什么是Http(s)
超文本传输协议(Hyper Text Transfer Protocol,HTTP)是一个简单的请求-响应协议,它通常运行在TCP之上。它指定了客户端可能发送给服务器什么样的消息以及得到什么样的响应。请求和响应消息的头以ASCII形式给出;而消息内容则具有一个类似MIME的格式。这个简单模型是早期Web成功的有功之臣,因为它使开发和部署非常地直截了当。
- HTTP:
- 文本:html,字符串,~~
- 超文本:图片,音乐,视频,定位,地图......
- 默认端口:80
- HTTPS:安全的
- 默认端口:443
2.Http的两个时代
- http1.0
- HTTP/1.0:客户端可以与web服务器连接后,只能获得一个web资源,断开连接
- http2.0
- HTTP/1.1:客户端可以与web服务器连接后,可以获得多个web资源
3.Http请求
- 客户端----发请求(Request)----服务器
百度:
Request URL: https://www.baidu.com/
//请求地址Request Method: GET
//get方法/post方法Status Code: 200 OK
//状态码:200Remote Address: 127.0.0.1:7890
//远程端口Referrer Policy: strict-origin-when-cross-origin
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
//设置语言Cache-Control: max-age=0
Connection: keep-alive
Cookie: BIDUPSID=10996A1BB6901B6DD084ADA2D7CBBD37; PSTM=1626322649; BD_UPN=12314753; __yjs_duid=1_a080e388f5c820ffdbd6c0424c03c8a51626349962371; H_WISE_SIDS=110085_114552_127969_164870_171234_175756_176398_176677_177167_177411_178328_178624_179349_179379_179450_180115_180407_180434_180436_180655_180863_180868_180914_180932_181207_181270_181328_181429_181434_181487_181587_181610_181713_181799_181824_181986_182023_182077_182190_182236_182271_182273_182298_182321_182383_182428_182529_182598_182661_182683_182778_182815_183001_183030_183068_183223_183235_183309_183327_183403_183431_183528_183548_183588_183714_183766_8000075_8000110_8000128_8000141_8000154_8000172_8000177_8000185_8000188; MAWEBCUID=web_wWBKDQVPLqOsNfBLmFhcUVqzHOHESMFQrCsMxClrauuaUNXCHW; BDUSS=t-aVdXc2hNdUpKOVNSWG4wczE0SThMZkU5ZXo0T3UxSU5GNWx4emg3VmprR2xoRVFBQUFBJCQAAAAAAAAAAAEAAADR6r5xVtCht9EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMDQmFjA0JhV0; BDUSS_BFESS=t-aVdXc2hNdUpKOVNSWG4wczE0SThMZkU5ZXo0T3UxSU5GNWx4emg3VmprR2xoRVFBQUFBJCQAAAAAAAAAAAEAAADR6r5xVtCht9EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMDQmFjA0JhV0; BCLID_BFESS=9346678435190160169; BDSFRCVID_BFESS=Mc-OJeC627ef_FvHiUKSuvPq_-igqqvTH6aoWfTACJGaQuudNAQoEG0PVx8g0K4b9HKgogKKLeOTHGCF_2uxOjjg8UtVJeC6EG0Ptf8g0f5; H_BDCLCKID_SF_BFESS=tb4q_K_hJID3HRjvMn__DT5QqxbXqMr2HmOZ0l8KtD3qex7D5x7E3fP95qjTbl4L2CvDQ4QmWIQHDU3I3MQTyx-_0qotKU6CLCO4KKJxQtPWeIJoj-KByMPshUJiBM7-Ban7KhOIXKohJh7FM4tW3J0ZyxomtfQxtNRJ0DnjtnLhbRO4-TFKjjQbjfK; BAIDUID=3922CC0F9F3BDD5964DEE4D0C412FF8F:FG=1; BAIDUID_BFESS=3922CC0F9F3BDD5964DEE4D0C412FF8F:FG=1; COOKIE_SESSION=298_0_8_8_41_14_1_0_8_8_0_6_10190_0_1_0_1636894045_0_1636894044%7C9%23244229_205_1636526873%7C9; BD_HOME=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; BD_CK_SAM=1; PSINO=1; H_PS_PSSID=34949_35106_31253_35048_34584_34505_34917_34812_26350_34970_34868_35115_35079; H_PS_645EC=da6aLvbz%2F5EfUWvqmPkO3lZyiyB0G3YRfDh0gPP0RbL7L42M2KPccW6L6aLEWmYqCRSA; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; baikeVisitId=540a416b-5777-4c66-a130-5076194d2a5f; ab_sr=1.0.1_ODFlNGY3YmU2N2EwMDA1Y2Y5ZDY0NmJmOTIyNjc4M2M4MzgyMWYyZGFhZTA2MWNjYmI2NDFkNDA5MzIzOGRkZTk5MmYzMGQzYzllMDk1NjYwMmFlMWQ4ZTZiMjNlZjY1MmQyN2JhMmEyMjkwZGYzYmJkNTcxYTE4ZmY3ZmEyN2Y2ZTEyYzhjZWE5NDExNDcwMDBiMTVmYmFlMGRjYTc2NzM2NWNlOGY0M2U0YTE1ZTQxOTA4ODg1NmFlNzNlNTU2; BA_HECTOR=010l21ak0h258l01rj1gp4rti0q
Host: www.baidu.com
sec-ch-ua: "Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
1.请求行
- 请求行中的方式:GET
- 请求方式:Get,Post,HEAD,DELETE,PUT,TRACT......
- Get:请求能携带的参数比较少,大小有限制,会在浏览器的URL地址栏显示数据,不安全,但高效
- Post:请求能携带的参数无限制,大小无限制,不会在浏览器的URL地址栏显示数据,安全,但不高效
2.消息头
Accept:高速浏览器,它所支持的数据类型
Accept-Encoding:支持哪种编码格式 GBK UTF-8 GB2312 ISO8856-1
Accept-Language: 告诉浏览器,它的语言环境
Cache-Control:缓存控制
Connection:告诉浏览器,请求完成是断开还是保持连接
HOST:主机......
4.Http响应
百度:
Bdpagetype: 2
Bdqid: 0xdd6ec2cc000af1ef
Cache-Control: private
//缓存控制Connection: keep-alive
//连接:保持活跃Content-Encoding: gzip
//编码Content-Type: text/html;charset=utf-8
//类型Date: Mon, 15 Nov 2021 14:33:24 GMT
Expires: Mon, 15 Nov 2021 14:33:24 GMT
Server: BWS/1.1
Set-Cookie: BDSVRTM=296; path=/
Set-Cookie: BD_HOME=1; path=/
Set-Cookie: H_PS_PSSID=34949_35106_31253_35048_34584_34505_34917_34812_26350_34970_34868_35115_35079; path=/; domain=.baidu.com
Strict-Transport-Security: max-age=172800
Traceid: 1636986804283802906615955904711250080239
Transfer-Encoding: chunked
X-Frame-Options: sameorigin
X-Ua-Compatible: IE=Edge,chrome=1
1.响应体
Accept:高速浏览器,它所支持的数据类型
Accept-Encoding:支持哪种编码格式 GBK UTF-8 GB2312 ISO8856-1
Accept-Language: 告诉浏览器,它的语言环境
Cache-Control:缓存控制
Connection:告诉浏览器,请求完成是断开还是保持连接
HOST:主机......
Refrush:告诉客户端多久刷新一次
Location:让网页重新定位
2.请求状态码
- 200:请求响应成功
- 3xx:请求重定向
- 重定向:你重新到我给你的新位置去
- 4xx:找不到资源
- 资源不存在
- 5xx:服务器代码错误 500
- 502:网关错误
Comments | NOTHING