On the difference between the post and get requests request packet

About the difference between post and get requests request packet

Many people prone to learning web knowledge when thinking of a kind of inertia that is to get that get data from the server; post is to submit data to the server. The reason for this thinking, probably when we learn object-oriented programming class learned get () method and set () method, easy to put this concept analogy to the concept of the HTTP protocol inside. Even to me with some work experience programmers are likely to produce this kind of thinking.

HTTP protocol is a network protocol runs on a computer network application layer. It is implemented by two procedures, a server, a client. To be able to access a website, you must use a server to store data for all relevant images, documents, programs, and so on. THHP server program on the server might be running on top of a machine, such as tomcat, nginx, and so on. We use the browser is the customer end, we in the address bar of your browser supports http protocol web server ip address or domain name, port number, and path, you can access the web server above pages.

HTTP protocol constraints of how communication between the web server and the client. Sending them through packet communication. The client sends a request message to the server, the server receives a request message according to the client's request, send a response message. This article focuses explain the difference and connection between the post and get methods.

First, get on the difference between post

Many people think of first
1, the biggest difference is the different parameters of the transmission mechanism, greater post capacity, more secure.
2, get under way, to pass parameters on the url address, there is a length limit. Under post way to pass parameters are placed in the body http transmission.
3, get and post requests for form submission is, get a display submit, post is implicit commit; security post to be high.

But there are other differences place

There is also a difference, simply say:

GET generates a TCP packet; generating the POST two TCP packets.

Long said:

For the GET request, the browser will http header and data sent together, the server response 200 (return data);

For POST, the browser transmits the first header, the server response 100 continue, the browser then transmits data, in response to the server 200 ok (return data).

In other words, GET only need to put the car trip to deliver the goods, while the POST have to run twice, the first trip, go to the server and say hello, "Hey, I want to wait for the next shipment to delivery, you open the door to greet me, "and then send the goods back to the past.

Because POST requires two steps, the time to consume a little more, it seems more effective than GET POST. So the team has recommended replacing GET POST to optimize site performance. But this is a pit! Jumped need to be cautious. why?

There are three reasons:

  1. GET and POST has its own semantics, not just mixed.

  2. According to the research, in the network environment is good, send a packet time difference between time and send the two packets basically ignored. And in the case of poor network environment, TCP packets over the two packet integrity verification, there is great advantage.

  3. Not all browsers will send two packets, Firefox is sent only once during POST.

At the request message and then say

First, a request message might look like this:

POST /path/of/resource HTTP/1.1 
Host: IP:PORT 
Authorization: Basic YXBpdXNlcjpmbnN0MTIzNA== 
User-Agent: curl/7.59.0 
Accept: / 
Content-Length: 31 

The first line we have seen, is the request line message. POST http request this representation is the post method. Then is the path, http protocol. The following methods may request: get post put delete head. The parameters are stored in the body post, rather get method does not. If you send a get request carries parameters, our argument will be reflected in the url.
By sending a get request curl:

curl -v -X GET -i “http://ip:port/path?aaa=1&bbb=44d”

Our argument will be the presence of the body in the request message:

POST /path HTTP/1.1 
Host: 10.167.157.49:5001 
Authorization: Basic YXBpdXNlcjpmbnN0MTIzNA== 
User-Agent: curl/7.59.0 
Accept: / 
Content-Length: 31 
Content-Type: application/x-www-form-urlencoded

upload completely sent off: 31 out of 31 bytes
HTTP 1.0, assume close after body

We can see from the above request message, upload a body.
Above, we can see a Web page http request when, post and get methods can submit the form to the server. But we generally see is a post method, only to protect the privacy of the data in the form, in order to prevent exposure of the user's input in the url. In fact, the get method can also submit the form, but the input form are reflected in the url in it.

Guess you like

Origin blog.csdn.net/weixin_43931047/article/details/90417166