What is a communication protocol?
A communication protocol is a description of the rules that computers must follow in order to communicate with each other. TCP/IP is a large set of different communication protocols. The HTTP protocol is just one of them.
What is HTTP?
Hypertext Transfer Protocol (HTTP) is designed to enable communication between clients and servers.
HTTP protocol responsibilities
-
HTTP is responsible for communication between a Web server and a Web browser.
-
HTTP is used to send requests from a Web client (browser) to a Web server and to return content (web pages) from a Web server to a Web client.
Similarities and differences between GET and POST methods
A common interview question is: What’s the difference between GET and POST? This leads us to focus on the differences and ignore the commonalities. Let’s take a look at the similarities and differences between the two methods.
The method of HTTP
methods | describe |
---|---|
GET | Used to request data from a specified resource |
POST | Used to send data to the server to create/update resources |
PUT | Used to send data to the server to create/update resources, the difference between POST and PUT is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, repeated calls to POST requests have the side effect of creating the same resource multiple times. |
HEAD | Essentially the same as get, but the response does not present data, but HTTP header information, mainly used to check the effectiveness of resources or hyperlinks or reachable, check whether the web page is changed or updated, get header information, especially suitable for limited speed and bandwidth. |
DELETE | Deletes the specified resource |
OPTIONS | Gets HTTP request methods supported by the HTTP server, allowing clients to view server performance, such as pre-checking when Ajax crosses domains. |
CONNECT | Reserved in HTTP/1.1 for proxy servers that can pipe connections. Is to take the server as a springboard, to visit other web pages and then return the data back, the connection is successful, you can normal get, POST. |
TRACE | The command output displays the requests received by the server for testing or diagnosis. Generally prohibited, to prevent malicious attacks or stolen information |
GET is different from POST
-
GET is harmless when the browser falls back, while POST resubmits the request.
-
The URL generated by GET can be bookmarked, but not by POST.
-
GET requests are actively cached by browsers, whereas POST requests are not, unless set manually.
-
GET requests can only be URL coded (Application/X-www-form-urlencoded), while POST supports multiple encoding methods
Application/X-www-form-urlencoded or multipart/form-data. Use multiple encodings for binary data. .
-
GET request parameters are retained in browser history, while parameters in POST are not.
-
The parameters that GET requests pass in the URL are limited in length (because browsers have limits on URL length, up to 2048 characters), whereas POST does not.
-
GET accepts only ASCII characters for the data type of the argument, while POST has no restrictions (binary data is allowed).
-
GET parameters are passed through the URL and are connected with each other by ampersand. POST is placed in the Request body, so GET requests are not secure and sensitive information will be exposed on the URL.
-
Another important difference between GET and POST is the number of packets sent. A GET request produces one TCP packet, while a POST request produces two TCP packets.
1. For GET requests, the browser sends HTTP headers and data together, and the server responds with 200.
2. For POST, the browser sends a header, the server responds with 100 continue, the browser sends data, and the server responds with 200 OK.
GET request process:
- The browser initiates a TCP connection request (first handshake)
- The server responds with a TCP connection (second handshake)
- The browser acknowledges and sends the GET request header and data (third handshake)
- The server returns a 200 OK response
POST request process:
- The browser initiates a TCP connection request (first handshake)
- The server responds with a TCP connection (second handshake)
- The browser confirms and sends the POST header (third handshake)
- The server returns a 100 Continue response
- Browser sends data
- The server returns a 200 OK response
GET and POST are the same
HTTP is a subprotocol based on TCP/IP. Therefore, GET and POST requests are the same in nature.
Common HTTP status codes
Status code | describe |
---|---|
200 | successful |
201 | The request succeeds and the server creates a new resource |
202 | The server has accepted the request but has not yet processed it |
203 | The request is being executed, but has not finished processing |
204 | The server successfully processed the request, but did not return anything |
301 | Permanent redirection |
302 | Temporary redirection |
303 | Indicates that the requested resource has been assigned a new URL and should be directed to the requested resource using the GET method |
304 | The local cache |
400 | Error request, server does not understand request syntax |
401 | Without permission, HTTP authentication is required |
403 | Server rejects request |
404 | The server could not find the requested resource |
500 + | Server Cause |
conclusion
The similarities and differences between GET and POST methods are summed up so much, the omissions are unavoidable, welcome everyone to correct, I will timely modify.