Programmers: I finally know the difference between post and get the

Industry well-known programmer said: For those monthly salary of thirty thousand or less, claiming IT engineer code farmers are, in fact, we never put them fall into the ranks of our IT engineers. Although they always IT engineer itself, but they are just wishful thinking.

His words aroused the anger I do not know how many (yards agriculture) programmers, but do nothing, then ask programmers code farmers.

Code farming: Do you know get and post requests in the end what is the difference?
Programmer: You see this will know.
Code farming: a monthly salary of thirty thousand of you?
Programmers: ah.
Code farming:? How do you do the
programmer: I dream to do

Foreword
This problem is almost time of the interview will be asked, is a common theme, but with continuous learning, there are a lot of understanding for previous errors, they still need to constantly sum up, learning While Learning, not a pleasure .

Get on and post, if you have qualified at least 200 words on Baidu one million results, everyone has everyone's thinking, of course, this is also my way of thinking, if there is some wrong conclusions, hoping to spray them. Continuous improvement in the criticism, saying the party of mutual encouragement: if meaningless criticism, then praise meaningless.
Article Directory
Introduction
01 Features
Features 1.1 http of
1.2 request methods
1.3 we are familiar with the difference between
02 Common Mistakes
2.1 Mistakes
2.2 Myth II
2.3 Myth
2.4 Myth: "GET generate a TCP packet; POST generates two TCP packets . "
3 HTTP status codes Appendix
3.1 status code 1xx
3.2 status code 2xx: success
3.3 status code 3xx: redirection
3.4 status code 4xx: client error
3.5 status server error code 5 **
01 features
1.1 http characteristics
based on tcp / IP, a network application layer protocol, hypertext transfer protocol hyperText transfer protocol
work: the client requests the server response mode
fast: stateless connecting
flexible: any object can be transmitted, the type of the object by the Content-type flag
requesting client request message format comprising: a request line (request line), the request header (header), a blank line, the data request

The server response in response also consists of four parts, namely: a status line, a message header, a blank line, the response body

1.2 Method Request
http request can request a variety of methods.
HTTP1.0 request defines three methods: GET, POST, and HEAD method.

HTTP1.1 five new request methods: OPTIONS, PUT, DELETE, TRACE, and CONNECT method.

HTTP2.0 new binary format (Binary Format), HTTP1.x text of the resolution is based. Parse text-based format protocol naturally occurring defects, there is diversity in forms of text, the robustness of the scene to do a lot to consider inevitable, binary is different, recognize only the combination of 0's and 1's. Based on this consideration HTTP2.0 decided to adopt the protocol parsing binary format, convenient and robust implementation.

Multiplexing (MULTIPLEXING), i.e. a shared connection, i.e., each request is a sharing mechanism is used as a connection. A request corresponds to a id, there may be a plurality of such connection request, each request may be connected to random mixed together, then the receiver may be attributed to their different request service ends according to a request which the request ID.

header compression, as described above said, to the previously mentioned HTTP1.x header with a lot of information, and is repeatedly transmitted every time, HTTP2.0 encoder used to reduce the size of the header to be transmitted, a communications their respective cache Fields table header, both to avoid duplicate transmission of the header, but also reduces the size to be transmitted.

Server push (server push), the same as SPDY, HTTP2.0 also have server push capabilities.
Reference link: https: //baike.baidu.com/item/HTTP%202.0/12520156 fr = aladdin?

1 GET request page information specified, and returns the entity body.
2 HEAD similar get request, but the response is not returned in the specific content, for obtaining the header
3 POST submit data processing request to the specified resource (e.g., file submission form or upload). Data contained in the request body. POST request may result in a revision to establish and / or existing resources to new resources.
4 PUT substituted document specified content transmitted from the data server to the client.
5 DELETE request to the server to delete the specified page.
6 CONNECT HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode.
7 OPTIONS allows the client to view server performance.
8 TRACE echo server requests received, mainly used for testing or diagnosis.
1.3 We are familiar with the difference between
the most common protocol http two methods GET and POST, actually there are a few answers to these points is not accurate

Cache request: GET can be cached, and the post will not

Favorite Bookmarks: GET can, and can not POST

Reserved browser history: GET can, and can not POST

Use: get used to retrieve data, post data for submitting

Security: post than get security

Request parameters: querystring get url is part of, post can bring. get the querystring (only supports urlencode coding), the parameter post is on the body (support multiple coding)

Length limit parameter request: get request length up to 1024kb, post no limit on request data

02 Common Mistakes

get and post misunderstanding
for common difference above, if the interview to say, there is definitely a lot of problems, just in the school when the interview has also been gulping said so, think back now before misperception, there are many new understanding.

2.1 misunderstanding
"use: get used to retrieve data, post data for submitting"

Once heard a saying: get replacement post to optimize site performance, although this argument Yes, indeed, get often used to retrieve the data, but also by some post ui framework used to retrieve the data, such as kendo ui in the grid, is to use the post to accept the data. So the conclusion is get, post uses will also be adapted to local conditions. If you have used the kendo UI, will find paging, filtering, custom parameters are included in the form data inside.

Request parameters
get a querystring (only supports urlencode coding), post is on body (support multiple encoding)
one kind of query parameters are part of the URL, and the GET, POST and other request methods are, no matter what kind of request methods are there must be URL, and the URL query is optional, dispensable.

2.2 Myth
"length limit parameter request: get request length up to 1024kb, post no restriction on the request data"

This sentence seems really no wrong ah, the rookie tutorial also say ah. Although there is no error on the literal meaning, but must be understood correctly. I want to say is GET method url parameter data submitted no size limit, no limit (not just the querystring length) length of the url http protocol, this restriction is limited to a particular browser and the server for his

The following is the maximum processing capacity of a variety of browsers and servers make some notes

The maximum limit IE browser to a URL to 2083 characters
Firefox (Browser): For Firefox browser URL length limit of 65,536 characters.
Safari (Browser): URL maximum length is limited to 80,000 characters.
Opera (Browser): URL maximum length is limited to 190,000 characters.
Google (chrome): URL maximum length is limited to 8182 characters.
Apache (Server): url can accept a maximum length of 8,192 characters.
Microsoft Internet Information Server (IIS): accept a maximum url length of 16,384 characters.
So in order to comply with the minimum standards of the best bad exceed 2083 characters all standard, url's (2k + 35). Of course, in doing client, url is not displayed to the user, but a procedure call, this time only charge the length of the web server impact. For the transfer of Chinese characters length after a final encoding characters are nine characters.

The most common form form form form the default browser, default content-type is application / x-www-form-urlencoded, the data will be submitted in accordance with key value fashion, jquery ajax default is that the content-type . Of course, adding querystring in a certain way post is acceptable to, but get in the way of added body parameters will not be able to successfully receive.

2.3 Myth
"post higher than get security."

Security here is relative, is not the true sense of security, data get submitted will be displayed on the url, the page will be cached browser, others view the history will see the submitted data, but will not post . Also get to submit data also may cause CSRF attacks.

2.4 Myth: "GET generate a TCP packet; POST generates two TCP packets."
It still has some difficulties to understand, in fact, no matter what kind of browser, sending POST when they are not with Expect head, server naturally will not send 100 continue. By capturing Packet found that although will be divided into two, body is sent immediately after the header, simply does not exist, "waiting for the server response," the he said.
From another perspective, TCP is the transport layer protocol. Someone asks you where the application layer protocol GET and POST so what's the difference between, say when you answer maybe not the same as sending data at the transport layer, determined people do not smoke you?
References: https: //zhuanlan.zhihu.com/p/25028045

3 http status code Appendix
3.1 Status Code 1xx
100 the Continue:
server receives only part of the request, but if the server does not reject the request, the client should continue to send the remaining requests.
101 Switching Protocols:
Server Protocol Conversion: The server converts a protocol to another to comply with customers' requests.
102: a WebDAV (RFC 2518):
extended status code, the representative processing execution will continue to be
3.2 status code 2xx: Success
200 is the OK:
(. Followed by a response to the document request GET and POST) request success
201 Created:
the request is created, and a new resource is created.
202 Accepted:
for processing a request has been accepted, but the process is not completed.
203 Non-authoritative Information:
Documentation has returned normally, but some of the response headers might be incorrect, because the use of a copy of the document.
204 No Content:
No new documents. The browser should continue to display the original document. If you regularly refresh the page, and new user documentation can be determined Servlet enough, this status code is very useful.
205 Reset Content:
No new documents. But browser should reset the content it displays. To force the browser to clear the form input.
206 Partial Content:
The client sends a GET request with a Range header, the server completes it.
3.3 Status Code 3xx: Redirection
300 Multiple Choices:
multiple choice. List of links. The user can select a link destination. It allows up to five addresses.
301 Moved Permanently:
The requested page has moved to a new url
302 Found:
The requested page has been temporarily transferred to a new url.
303 See Other:
The requested page can be found under other url.
304 Not Modified:
modify the document not work as expected. Client has cached document and sends a request condition of (typically provided If-Modified-Since header indicates that the client document just newer than the date specified). Server told clients that the original document buffer can continue to use.
305 Use Proxy:
Requested document should be extracted through a proxy server specified in the Location header.
306 Unused:
This code is for a previous version. It is no longer used, but the code is still retained.
307 Temporary Redirect:
the requested page has been temporarily moved to a new url.
3.4 status code 4xx: Client Error
400 Bad Request:
server failed to understand the request.
401 Unauthorized:
the requested page requires a user name and password.
401.1:
Logon failed.
401.2:
Server Configuration Logon failed due.
401.3:
Due to ACL on resource without authorization.
401.4:
Authorization failed by filter.
401.5:
ISAPI / CGI application authorization failure.
401.7:
Access denied URL authorization policy on the Web server. This error code is specific to IIS 6.0.
402 Payment Required:
This code is not available.
403 Forbidden:
Access to the requested page is forbidden.
404 Not Found:
The server could not find the requested page.
405 Method Not Allowed:
The method specified in the request is not allowed.
406 Not Acceptable:
the server generates a response can not be accepted by the client.
407 Proxy Authentication Required:
the user must first use a proxy server for authentication, so that the request will be processed.
408 Request Timeout:
request exceeds the waiting time server.
409 Conflict:
Due to the conflict, request can not be completed.
410 Gone:
the requested page is not available.
The Length the Required 411:
"Content-the Length" is not defined. If no such content, the server will not accept the request.
412 Precondition Failed:
Prerequisites request is evaluated as a server failure.
413 Request Entity Too Large:
Because much of the requested entity, the server will not accept the request.
414 Request-url Too Long:
because the url is too long, the server does not accept the request. When the request is converted to a post with a long query information get request, this situation occurs.
415 Unsupported Media Type:
Since the media type is not supported, the server will not accept the request.
416 Requested Range Not Satisfiable:
server can not meet customer specified in the request Range header.
417 Expectation Failed:
failed to execute.
423:
Locked error.
5 3.5 ** status code error server
500 Internal Server Error:
request was not completed. The server encountered unforeseen circumstances.
501 Not Implemented:
request was not completed. Server does not support the requested function.
502 Bad Gateway:
request was not completed. Server received an invalid response from the upstream server.
503 Service Unavailable:
the request was not completed. Temporary overloading or server downtime.
504 Gateway Timeout:
Gateway timeout.
505 HTTP Version Not Supported:
The server does not support the HTTP protocol version specified in the request.

Guess you like

Origin www.cnblogs.com/gfgfe45/p/12147860.html