Every time I write an article, I don't know how to get a name with a slight connotation. If this article is just about the difference between get and post, I can name it "Get and post". If you want to elaborate on the principles of the HTTP protocol, it should be called "What you don't know in HTTP ", neither of them is what I want. The former is too simple, and the latter is too esoteric and beyond my own capabilities. Therefore, I can only write HTTP, get, post and slack. Let's take a look at it. There are a lot of nonsense problems at the beginning. I find it increasingly difficult for me to change it. Let's get started ~
HTTP
HTTP (Hypertext Transfer Protocol): First, let's talk about a few words. hypertext is hypertext (in addition to HTML, it can also be XML or JSON with hyperlinks), and Protocol is protocol, transfer translation should be handed over (it can also be translated into transmission and transportation, and another more specific word is transport ), at first, the school translated all the books that can be seen on the market of HTTP into the ultra-text transmission protocol. Http was designed to transfer and operate resources, not to transmit resources. the initial website was static content similar to today's cloud disk, achieving resource sharing. The URL (Uniform Resoure locator: Unified Resource Locator) is used to map online resources, to allow unified access to web resources, HTTP provides several methods to access resources.
The HTTP protocol defines eight methods for interaction with the server: Get (obtain resources), post (submit data to a specified resource for processing requests, add or update resources ), put (upload the latest content to the specified resource location), delete (request the server to delete the resource identified by request-Uri );
Head (the host responds to some data file headers on the client) and options (the host responds to some allowed functions and methods on the client. Returns the HTTP Request Method supported by the server for a specific resource. You can also send a '*' request to the Web server to test the server's functionality. Trace (echo the request received by the server, mainly used for testing or diagnosis ), connect (the HTTP/1.1 protocol is reserved for proxy servers that can change connections to pipelines ). When I went out for an interview, I only knew there were get and post requests. I don't know anything else. Now I think it's a bit embarrassing.
Basic concepts of get and post
HTTP itself is a resource-oriented application layer protocol, but there are actually two different ways to use http: one is restful, which regards HTTP as an application layer protocol, the other is SOA, which does not fully regard HTTP as an application layer protocol, but uses HTTP as a transport layer protocol, then, an application layer protocol is built on HTTP.
Speaking of this, I have to talk about Roy Thomas Fielding, a great man. He has a detailed introduction in English on the Wiki. I want to talk about Chinese. He is an HTTP protocol (version 1.0 and Version 1.1) one of the major designers of Apache server software, and the first Chairman of the Apache Foundation. Based on the above work experience, he wrote an amazing doctoral thesis titled architectural styles and the design of network-based software ubuntures, architectural style and Architecture Design Based on Network Application Software (download link: http://pan.baidu.com/s/1bnGQUsv ).
A rest (representational state transfer) architecture is proposed in this paper. It corresponds to the above restful usage method, which has not been used in the project. After reading the 1.1-point fur, you can study it yourself if you are interested ~ Get and post are widely used. In the interview, basically the same as recursion, it is about opening up the conversation on a common topic. Let's look at the concept ~
1. According to the initial HTTP protocol design, get is used to obtain resources and should be secure and idempotent.
Security and power are semantic. Just as the compiler can only help check syntax errors, HTTP standards cannot be defined by syntax means such as message format. According to the rules, get is only used to obtain server resources. However, if you use get to perform other operations, it will not be affected even if it violates the rules. Idempotence is a concept in mathematics. Let's briefly describe it:
The result of a one-dimensional operation is the same as that of an element after two times. For example, the absolute value of A is equal to a, ABS (A) = ABS ()). In binary operations, idempotence means that the result of repeated operations (or compound functions) is equal to its own element. For example, the only two idempotent real numbers under multiplication are 0 and 1, 0*0 = 0.
2. According to the initial HTTP protocol design, post is used to add or update resources.
Similarities and differences between get and post
You can search for similarities and differences on the Internet. If you want to write them all over the street, you can try to compare them as per your understanding:
1.VisibilityThe URL is visible to all users during get access, and post is invisible.
2.Length limit. There is no limit on the Transfer Length of get and post.(I don't know if I didn't learn it well at the time, or the teacher mistakenly said that the GET request has a length limit. For a long time, I thought the GET request length was 1 kb.) The GET request was sent along with the URL, the browser limits the URL length, so the parameters passed by get cannot be too long. the URL does not have a parameter limit. The HTTP protocol does not limit the URL length. Only browser restrictions are imposed. Different browsers have different restrictions. The maximum URL limit of IE is 2083 characters. If this number is exceeded, the submit button does not respond. The URL Length of the Firefox browser is limited to 65,536 characters, but when I test it, it can only process a maximum of 8182 characters, because the URL length is not limited by the browser, it is also limited by Web servers. The maximum length of a URL in Safari is 80,000 characters. The maximum length of operaurl is 190,000 characters. Chrome has a URL length limit of 8182 characters.
There is no limit on the size of the POST request. The web server will control the POST request. The iis7 is used as an example.
Find iis_schema.xml in the following path: c: \ windows \ system32 \ inetsrv \ config \ schema. Search for name = "requestlimits" and you will see three configurations.
<Attribute name = "maxallowedcontentlength" type = "uint" defaultvalue = "30000000"/>
<Attribute name = "maxurl" type = "uint" defaultvalue = "4096"/>
<Attribute name = "maxquerystring" type = "uint" defaultvalue = "2048"/>
Postiis requests are limited to a maximum of 28.6 MB, and get requests are limited to 2 kb. You can modify the length as needed.
3.Security, Compared with post, get is less secure, because the data sent is part of the URL (no one should use get when submitting data at login), and post is safer than get, because parameters are not stored in browser history or web server logs.
4.Data Type, Get only supports ASCII characters, there is no limit on post transmission, and binary data is also allowed.
5.Encoding typeThe enctype attribute of form is the content encoding method of form controls. There are two common types: Application/X-WWW-form-urlencoded (default) and multipart/form-data, both get and post encoding methods can be used. When a form contains a type = file control, only post can be used for sending, the content encoding method can only use multipart/form-data.
6.Bookmarks, CacheGET requests can be added as bookmarks and cached. POST requests cannot be added as bookmarks or cached.
7.Value Method, Asp.. net. querystring value, which is used for post requests. form value. If you are lazy, use the common request method. jsp uses the request method for get requests. querystring (""); value, which is used for post requests. getparameter (""); value, you can also directly use request. getparameter ("") gets the data in the GET request. in PHP, you can use $ _ Get and $ _ post to obtain data in get and Post respectively, while $ _ request can obtain data in get and post requests.
Suddenly, I wrote something casually for a week, and it was inevitable that something was missing or improperly understood. please correct me a lot and wish everyone a good mood on Monday ~
[References]
Http://www.infoq.com/cn/minibooks/dissertation-rest-cn
Http://www.infoq.com/cn/minibooks/web-based-apps-archit-design