HTTP

*概念:Hyper Text Transfer Protocol 超文本传输协议

  *传输协议:定义了客户端和服务器通信时,发送数据的格式

  *特点:

    1.基于TCP/IP的高级协议

    2.默认端口号:80

    3.基于请求/响应模型的的:一次请求对应一次响应

    4.无状态的:每次请求之间相互独立,不能相互交互

*历史版本

  1.0:每次请求响应都会建立新的链接

  1.1:复用链接

*请求消息的数据格式:

    1. 请求 URL:
      http://localhost:8080/demo1_war_exploded/aaa.html
    2. 请求方法:
      POST
    3. 状态代码:
      200
    4. 远程地址:
      [::1]:8080
    5. 引用者策略:
      strict-origin-when-cross-origin
  1. 响应头查看源
    1. Accept-Ranges:
      bytes
    2. Connection:
      keep-alive
    3. Content-Length:
      236
    4. Content-Type:
      text/html
    5. Date:
      Fri, 06 Jan 2023 16:44:32 GMT
    6. ETag:
      W/"236-1673023275087"
    7. Keep-Alive:
      timeout=20
    8. Last-Modified:
      Fri, 06 Jan 2023 16:41:15 GMT
  2. 请求标头查看源
    1. 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
    2. Accept-Encoding:
      gzip, deflate, br
    3. Accept-Language:
      zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
    4. Cache-Control:
      max-age=0
    5. Connection:
      keep-alive
    6. Content-Length:
      11
    7. Content-Type:
      application/x-www-form-urlencoded
    8. Cookie:
      JSESSIONID=31C72F1D9809162C7162A4AD8844F3E6; Idea-2a398c=5a481628-2bad-4c5f-9124-e78b51143638
    9. Host:
      localhost:8080
    10. Origin:
      http://localhost:8080
    11. Referer:
      http://localhost:8080/demo1_war_exploded/aaa.html
    12. sec-ch-ua:
      "Not?A_Brand";v="8", "Chromium";v="108", "Microsoft Edge";v="108"
    13. sec-ch-ua-mobile:
      ?0
    14. sec-ch-ua-platform:
      "Windows"
    15. Sec-Fetch-Dest:
      document
    16. Sec-Fetch-Mode:
      navigate
    17. Sec-Fetch-Site: 
      same-origin
    18. Sec-Fetch-User:
      ?1
    19. Upgrade-Insecure-Requests:
      1
    20. User-Agent:
      Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54

 

  1.请求行

    GET:

      1. 请求参数在请求行中,在url后

      2.请求的url长度有限制

      3.不太安全

    POST:

      1.请求参数在请求体中

      2.请求的url长度没有限制的

      3.相对安全 

  2.请求头

    *常见的请求头:

      user-Agent:浏览器告诉服务器,我访问你使用的浏览器版本信息

        *可以在服务器端获取该头的信息,解决浏览器的兼容性问题

      2.referer:http://localhost/login.html

        *告诉服务器,当前请求从哪里来

          *作用:1.防盗链   2.统计工作

  3.请求空行

  4.请求体

*响应消息的数据格式:

1.相应行

    1.组成:协议/版本 响应状态码 状态码描述

    2.响应状态码:服务器告诉客户端浏览器本次请求和响应的一个状态

      1.状态码都是3位数字  

      2.分类:

        1xx:服务器就收客户端消息,但没有接受完成,等待一段时间后,发送1xx多状态码

        2xx:成功。代表200

        3xx:重定向。代表:302

        4xx:客户端错误。代表404(没有对应的资源)405(请求方式没有对应doxxx方法)

        5xx:服务器端错误。代表:500(服务端异常)

2.响应空行

3.响应体:传输的数据

4.响应头:

  格式:头名称  :值

  2.常见响应头:

    1.Content-Type: text/html;charset=utf-8:服务器告诉客户端本次响应体数据格式以及编码格式

    2.Content-disposition:服务器告诉客户端以什么格式打开响应体数据

 

 

HTTP/1.1 200 OK

Cache-Control: private

Connection: keep-alive

Content-Encoding: gzip

Content-Type: text/html;charset=utf-8

Date: Sat, 07 Jan 2023 15:23:41 GMT Expires: Sat, 07 Jan 2023 15:23:41 GMT

Server: BWS/1.0

Vary: Accept-Encoding

Transfer-Encoding: chunked

 

     

posted @ 2023-01-07 00:51  会秃头的小白  阅读(90)  评论(0)    收藏  举报