HTTP的请求协议

113 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

前言:带领大家走进HTTP后,今天带领大家看看HTTP是怎么请求的~

    • HTTP协议就是提前制定好的一种消息模板。

      • 不管你是哪个品牌的浏览器,都是这么发。
      • 不管你是哪个品牌的WEB服务器,都是这么发。
      • FF浏览器 可以向 Tomcat发送请求,也可以向Jetty服务器发送请求。浏览器不依赖具体的服务器品牌。
      • WEB服务器也不依赖具体的浏览器品牌。可以是FF浏览器,也可以是Chrome浏览器,可以是IE,都行。
    • HTTP的请求协议(B --> S)

      • HTTP的请求协议包括:4部分

        • 请求行
        • 请求头
        • 空白行
        • 请求体
      • HTTP请求协议的具体报文:GET请求

        • GET /servlet05/getServlet?username=lucy&userpwd=1111 HTTP/1.1                           请求行
          Host: localhost:8080                                                                    请求头
          Connection: keep-alive
          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"
          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.54 Safari/537.36
          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
          Sec-Fetch-Site: same-origin
          Sec-Fetch-Mode: navigate
          Sec-Fetch-User: ?1
          Sec-Fetch-Dest: document
          Referer: http://localhost:8080/servlet05/index.html
          Accept-Encoding: gzip, deflate, br
          Accept-Language: zh-CN,zh;q=0.9
                                                                                                  空白行
                                                                                                  请求体
          
      • HTTP请求协议的具体报文:POST请求

        • POST /servlet05/postServlet HTTP/1.1                                                  请求行
          Host: localhost:8080                                                                  请求头
          Connection: keep-alive
          Content-Length: 25
          Cache-Control: max-age=0
          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"
          Upgrade-Insecure-Requests: 1
          Origin: http://localhost:8080
          Content-Type: application/x-www-form-urlencoded
          User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
          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
          Sec-Fetch-Site: same-origin
          Sec-Fetch-Mode: navigate
          Sec-Fetch-User: ?1
          Sec-Fetch-Dest: document
          Referer: http://localhost:8080/servlet05/index.html
          Accept-Encoding: gzip, deflate, br
          Accept-Language: zh-CN,zh;q=0.9
                                                                                                空白行
          username=lisi&userpwd=123                                                             请求体