【学习笔记】HTTP

HTTP

 

什么是http

  • HTTP:超文本传输协议,是一个简单的请求-相应协议

    • 超文本:图片、视频、音乐、定位

    • 默认端口:80

  • HTTPS:以安全为目标的HTTP通道,在HTTP的基础上加入了SSL,保证了传输过程的安全性

    • 默认端口:443

 

HTTP的两个时代:

  • http1.0

    • http/1.0:客户端与web服务器连接后,只能获得一个web资源,然后断开连接

  • http2.0

    • http/2.0:客户端与服务器连接后,可以获得多个web资源

 

请求与相应

以访问百度为例

  • 常规

    请求 URL: https://www.baidu.com/
    请求方法: GET
    状态代码: 200 OK
    远程地址: 110.242.68.4:443
    引用者策略: strict-origin-when-cross-origin

     

响应头

Bdpagetype: 2
Bdqid: 0xba83753500003c54
Cache-Control: private        --- 缓存控制
Connection: keep-alive        --- 连接
Content-Encoding: gzip        --- 编码
Content-Type: text/html;charset=utf-8
Date: Mon, 10 Oct 2022 07:09:05 GMT
Expires: Mon, 10 Oct 2022 07:09:05 GMT
Isprivate: 1
Server: BWS/1.1
Set-Cookie: BDSVRTM=368; path=/
Set-Cookie: BD_HOME=1; path=/
Set-Cookie: H_PS_PSSID=37378_36560_37561_37357_37300_36884_37403_37404_36789_37498_26350_37489_37372_37466; path=/; domain=.baidu.com
Strict-Transport-Security: max-age=172800
Traceid: 1665385745235747149813439714583497423956
Transfer-Encoding: chunked
X-Frame-Options: sameorigin
X-Ua-Compatible: IE=Edge,chrome=1

比较重要的:

Cache-Control: private --- 缓存控制 Connection: keep-alive --- 连接 Content-Encoding: gzip --- 编码 Content-Type: text/html;charset=utf-8 --- 类型

 

响应状态码

200:请求成功 200

3xx:请求重定向,即重新定位,

4xx:找不到资源 404

5xx:服务器代码错误 500 502:网关错误

 

重定向:比如微博,如果你去请求一个不存在的资源:12354568.html,它会自动给你跳转到

2F132156dfsf.html,状态码是302,即重定向

具有重定向的网站会进行重定向,不具有重定向的网站则会报出Not Found,状态码是404

 

 

请求头

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,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,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Cache-Control: max-age=0
Connection: keep-alive
Cookie: BDUSS=hESUJFSjE1SUhQYVlKWGppM0U1emd6aEQ3bXA0bWgxckRYSm1RWHI3b0xYN1JpRVFBQUFBJCQAAAAAAAAAAAEAAABglJtNuf4xMTIyNQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAvSjGIL0oxiVm; BDUSS_BFESS=hESUJFSjE1SUhQYVlKWGppM0U1emd6aEQ3bXA0bWgxckRYSm1RWHI3b0xYN1JpRVFBQUFBJCQAAAAAAAAAAAEAAABglJtNuf4xMTIyNQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAvSjGIL0oxiVm; BAIDUID=210604ED9BD399558DAD689C6364778D:FG=1; BIDUPSID=210604ED9BD399558DAD689C6364778D; PSTM=1654758697; BD_UPN=12314753; newlogin=1; ispeed=1; BAIDUID_BFESS=210604ED9BD399558DAD689C6364778D:FG=1; ZFY=kPWtjQDnAB:BFaNV4diq436h8vE0ztKlQ:B4l0nVJlBYI:C; ispeed_lsm=35; delPer=0; BD_CK_SAM=1; PSINO=2; H_PS_PSSID=37378_36560_37561_37357_37300_36884_37403_37404_36789_37498_26350_37489_37372_37466; B64_BOT=1; BA_HECTOR=80ah2h2l85810g84a50l505d1hk7gtb1b; RT="z=1&dm=baidu.com&si=wkpqgm95n&ss=l92fgk8t&sl=3&tt=88a&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=dp3&ul=27ye&hd=281x"; BD_HOME=1; H_PS_645EC=38a9LNYfk1nluIg7d10OwgYiy82vo6lBzGes5XFnxGPc%2B0mzGgQNZlhNNB4; sugstore=0
Host: www.baidu.com
sec-ch-ua: "Chromium";v="106", "Microsoft Edge";v="106", "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: cross-site
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/106.0.0.0 Safari/537.36 Edg/106.0.1370.34

比较重要的:

Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6 Cache-Control: max-age=0 Connection: keep-alive

 

请求方式

  • GET、POST、HEAD、DELETE、PUT、TRACT

  • 常用的有get和post

    • get:请求能够携带的参数较少,大小有限制,会在浏览器的URL地址栏显示数据内容,不安全但高效

    • post:请求能够携带的参数没有限制,大小没有限制,不会在浏览器的URL地址栏显示数据内容,安全但不高效,但现在网络今非昔比,所以可以忽略两者的效率差距

posted @ 2022-10-10 15:33  GrowthRoad  阅读(99)  评论(0编辑  收藏  举报