Home  >  Article  >  What is the difference between post and get requests?

What is the difference between post and get requests?

青灯夜游
青灯夜游Original
2023-02-03 11:23:1078556browse

Difference: 1. Post request is more secure; post request will not be used as part of the URL, will not be cached, saved in server logs, and browser browsing records. If the get request is a static resource, it will Cache, if it is data, it will not be cached. 2. The data sent by the post request is larger, and the get request has a URL length limit. 3. The post request can send more data types, while the get request can only send ASCII characters. 4. The methods of parameter transmission are different. 5. Get generates one TCP packet; post generates two.

What is the difference between post and get requests?

The operating environment of this tutorial: Windows 10 system, Dell G3 computer.

Get request: Request data from a specified resource, used to obtain data, generally used for operations such as search sorting and filtering.

Post request: Submit the data to be processed to the specified resource, used to send the data to the server, generally used to modify and write data.

Get requests and post requests are essentially TCP links and there is no difference. However, due to HTTP regulations and browser/server limitations, they show some differences in the application process.

The difference between post request and get request

(1) post request is more secure (will not be part of the url and will not be cached) , saved in server logs and browser browsing records. If the get request is a static resource, it will be cached. If it is data, it will not be cached.)

(2) The data sent by the post request is larger ( The get request has a URL length limit, the http protocol itself does not limit the request length limit is determined and set by the browser and web server)

(3) The post request can send more data types (get requests can only Send ASCII characters)

(4) The parameter passing methods are different (get request parameters are passed through the url, and the post request is passed in the request body)

(5) The get request generates a TCP packet ; Post request generates two TCP data packets (get request, the browser will send the http header and data together, the server responds with 200 to return the data; post request, the browser sends the header first, the server responds with 100 continue, and the browser then sends data, the server responds with 200 and returns data)

Note: There is no Expect header when sending POST, and the server will naturally not send 100 continue.

Post request process:

(1) The browser requests a tcp connection (first handshake)

( 2) The server agrees to make a TCP connection (the second handshake)

(3) The browser confirms and sends the post request header (the third handshake, this message is relatively small, so http will be processed at this time First data sending)

(4) The server returns 100 Continue response

(5) The browser sends data

(6) The server returns 200 OK response

Get request process:

(1) Browser requests tcp connection (first handshake)

(2) Server Agree to TCP connection (second handshake)

(3) The browser confirms and sends the get request header and data (the third handshake, this message is relatively small, so http will perform the third handshake at this time One data transmission)

(4) The server returns a 200 OK response

If the network environment is good, the difference in time between sending a packet once and sending two packets can basically be ignored. In the case of poor network environment, TCP with two packets has great advantages in verifying the integrity of data packets.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What is the difference between post and get requests?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn