An overview,

See this article again: juejin.cn/post/684490…

The conclusion of this article is:

GET generates a TCP packet. POST generates two TCP packets.

  • For a GET request, the browser sends the HTTP header and data together, and the server responds with 200 (returning data).

  • For POST, the browser sends a header, the server responds with 100 continue, the browser sends data, and the server responds with 200 (returning data).

So I thought I’d test it out.

First, the results:

  1. simplePOSTRequest, produce oneTCPPackage (corresponding concept)
  2. The requested data is too large, and the client sends the data firstheaderRequest and carryExpect: 100-continue, the server respondsHTTP / 1.1 100Before the actual request data is sent
  3. The concept:TCPIs streaming




Second, the experimental

Experimental steps:

  1. Start the service on port 8081
  2. Start thewiresharkTo filter the corresponding ports
    • GETrequest
    • POSTrequest

(1) Start the service on port 8081

Using SpringBoot, start the service:

Tips: Is launched locally.

@RestController
class HelloController {

    @GetMapping("/test/1")
    public String test1(a) {

        return "123";
    }

    @PostMapping("/test/2")
    public String test2(@RequestBody Object o) {

        System.out.println(o.toString());

        return "456"; }}Copy the code

(2) StartwiresharkTo filter the corresponding ports

Since it is a local request to access the local service, select the loopback interface (local return), as shown in the figure:

Filter port: Port 8081, as shown in the figure:

The example is a GET request

  • []: indicates a connection
  • ->: Request
  • <-: indicates return
  1. GETrequest

Request:

donald@donald-pro:~$ curl http://localhost:8081/test/1 -i HTTP/1.1 200 content-type: text/plain; charset=UTF-8 Content-Length: 3 Date: Fri, 12 Mar 2021 01:51:35 GMT 123Copy the code

wiresharkThe packet capture results are as follows:

  1. POSTrequest

Request:

donald@donald-pro:~$ curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name": "donald"}' http://localhost:8081/test/2 -i HTTP/1.1 200 content-type: application/json; /2 -i HTTP/1.1 200 content-type: application/json; charset=UTF-8 Content-Length: 3 Date: Fri, 12 Mar 2021 02:08:27 GMT 456Copy the code

The Wireshark captures packets as follows:

Is that bag not big enough?

Ask again:

donald@donald-pro:~$ curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name": "donald", "data": "iVBORw0KGgoAAAANSUhEUgAAAhwAAA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APd89zFwJjjAAAAABzIK1dAAAAiVBORw0KGgoAAAANSUhEUgAAAhwAAAHkCAIAAAD6tWHCAAAACXBIWXMAAA7 EAAAOxAGVKw4bAAAgAElEQVR4nOzdd1wT5x8H8OcuO4SwNwioiOBCBbd1b61ba7V1oNZta20VF4K21lVrHWirVisO1J+Kq7bOuq0DB0NFEZANCZC97p7fH1f TCIjYxkTN9/3yj+TJc5fvnZAPd89zFwJjjAAAAABzIK1dAAAA"}' http://localhost:8081/test/2 -i HTTP/1.1 100 HTTP/1.1 200 Content-type: application/json; /2 -i HTTP/1.1 100 HTTP/1.1 200 Content-type: application/json; charset=UTF-8 Content-Length: 3 Date: Fri, 12 Mar 2021 02:45:16 GMT 456Copy the code

The Wireshark captures packets as follows:

You can see that there is an HTTP 100.

However, the semantics of the HTTP status code 100 are:

  • 100 Continue: Used before uploading large files

Triggered by the Expect: 100-continue header in a client request.

It does send the header first, with Expect: 100-continue, as shown here: