A brief talk on Get and post in HTTP protocol

Source: Internet
Author: User
Tags abs http request log representational state transfer resource

Http

HTTP (Hypertext Transfer Protocol), first say a few words, hypertext is hypertext (in addition to HTML, can also be hyperlinked XML or JSON), Protocol is protocol, transfer translation should be transferred (can also be translated into transmission, transport, and there is a more specific word is transport), the first school to learn HTTP all the available books are translated into Hypertext Transfer Protocol, HTTP design itself is to transfer and manipulate resources, It's not about transferring resources. The first sites are static content similar to today's cloud disk, the implementation of resource sharing, URL (uniform resoure Locator: Uniform Resource Locator) to map the resources on the web, in order to be able to access a unified network resources, HTTP provides several ways to access resources.

The HTTP protocol defines eight methods for interacting with the server: Get (Fetch resources), post (submit data to the 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 the Request-uri);

Head (host side responds to some data file headers on the client side), options (host side responds to some of the allowed functions and methods on the client side). Returns the HTTP request method that the server supports for specific resources. You can also use a request to send a ' * ' to the Web server to test the functionality of the server, trace (the request received by the Echo server is primarily for testing or diagnostics), and connect (the http/1.1 protocol is reserved for a proxy server that can change the connection to a pipe). I used to go out for an interview only to know that there are get and post requests, for others do not know, now want to feel a little ashamed.

Basic concepts of Get and post

The HTTP protocol itself is a resource-oriented application layer protocol, but there are actually two different ways of using HTTP protocol: One is restful, it treats HTTP as an application layer protocol, more faithfully adheres to the various rules of HTTP protocol, and the other is SOA, Instead of using HTTP as the Application layer protocol, the HTTP protocol is used as the Transport layer protocol, and then the application layer protocol is established on top of HTTP.

Speaking of which, we have to talk about a man of great divinity. Roy Thomas Fielding, Wikipedia has a detailed English introduction, I said in Chinese, he is the HTTP protocol (version 1.0 and 1.1), the main designer, Apache Server Software, one of the authors, The first president of the Apache Foundation. Based on the above work experience he wrote an amazing doctoral dissertation architectural Styles and the design of network-based Software architectures, Architecture Design (DOWNLOAD link: http://pan.baidu.com/s/1bnGQUsv) in Chinese called Architecture style and web-based application software.

In this paper, a rest (representational state transfer) architecture is proposed. That corresponds to the way the restful is used, the project has not been used, saw 1.1 points of fur, friends interested in their own study of the ~get and post the two brothers used too wide, and the interview is basically like recursion is to open the common topic of conversation, or to see the concept of it ~

1. According to the initial HTTP protocol design, get is used to obtain resources, and should be secure and idempotent.

Security and idempotent belong to the semantic category, just as the compiler can only help check for grammatical errors, and the HTTP specification has no way to define it by grammatical means such as message format. By specification, get is used only to obtain server resources, but you perform other operations with gets, which, while violating the specification, will not be affected. Power is the concept of mathematics, simple to say:

A unary operation has the same effect on any element two times as the result of its function once. For example, the absolute value of a is equal to A,abs (a) =abs (ABS (a)). In binary operations, idempotent elements are those that are repeated by themselves (or in the case of a function being compound) 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 design of the initial HTTP protocol, post is used to increase resources or update resources.

Similarities and differences between get and post

Similarities and differences point online casually look for, full street are, since to write, I still unavoidable vulgar, as far as possible in accordance with their own understanding of the way to compare:

1. Visibility, the URL is visible to everyone when the get is accessed, and post is invisible.

2. Length limit, get and post delivery length are unlimited (do not know whether they were not good at the time or the teacher fraught said got is a length limit, for a long time, a GET request is 1kb in length, and getting is requested with the URL, and the browser limits the length of the URL. The argument that caused the get pass cannot be too long. The URL does not have a problem with the upper parameter limit, and the HTTP protocol specification does not limit the URL length. Only browser restrictions, different browser restrictions, ie browser to the maximum URL limit of 2,083 characters, if more than this number, the Submit button has no response. The length of the Firefox browser URL is limited to 65,536 characters, but when I test it, it can only handle 8,182 characters, because the length of the URL is limited by the Web server in addition to the browser restrictions. The maximum length of a URL in Safari is limited to 80,000 characters. Operaurl Maximum length limit is 190,000 characters. Chrome limits the URL length to 8,182 characters.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/web/Skills/

Post is the request size is unrestricted, the Web server will control the POST request, take IIS7 as an example

In the following path C:\Windows\System32\inetsrv\config\schema find Iis_schema.xml, search for Name= "RequestLimits", you will see three configurations.

<attribute name= "maxAllowedContentLength" type= "uint" defaultvalue= "30000000"/> "<attribute" name= "MaxUrl" Ty Pe= "UINT" defaultvalue= "4096"/> <attribute name= "maxquerystring" type= "UINT" defaultvalue= "2048"/>

The Postiis request is limited to a maximum of 28.6m,get request IIS limit of 2KB and, if necessary, can be modified to the size of the length.

3. Security, compared to post, get is less secure because the data sent is part of the URL (the data submitted should not be used with get when you log in), and post is more secure than get because the parameters are not saved in the browser history or Web server log.

4. Data type, get only allow ASCII characters, post delivery is not limited, also allow binary data.

5. Encoding type, form's Enctype property is the form control's content encoding way, commonly has two kinds: application/x-www-form-urlencoded (default) and Multipart/form-data, Either get or post can use both encodings, and when the form contains the Type=file file control, the method can only be sent using post, and content encoding can only be done using Multipart/form-data.

6. Bookmarks, caches, get requests can be stored as bookmarks, can be cached, post can not be collected as bookmarks, can not be cached.

7. Value method, ASP. NET to get request use Request.QueryString value, to POST request use Request.Form value, if lazy words directly with request both general, JSP to get request use Request.QueryString ( ""); value, use Request.getparameter ("") for post requests, or you can use Request.getparameter ("") to get the data in the getting request directly. In PHP, you can use $_get and $_ Post gets the data in Get and post, respectively, and $_request gets the data from the get and post two requests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.