The difference between get and post

Source: Internet
Author: User
Tags html header alphanumeric characters

The difference between post and get

post  Address bar does not appear a large list of things like Bjnghfgreygt

If it's a get, it's going to happen.

1, the Get method passes the user's data through a URL request, connects the field names in the form with their contents, paired strings, and places the URL of the program that the Action property refers to, such as [url]http://www.mdm.com/test.asp? Name=asd&password=sad[/url], the data will be displayed directly on the URL, just as the user clicks on a link, and the Post method uses the HTTP post mechanism to place the name of each field in the form with its contents in the HTML header (header) Sent to the server by the Action property can refer to the program processing, the program through the standard input (stdin), the form of the data read out and processed


2, the Get method needs to use Request.QueryString To get the value of the variable, and post through Request.Form to access the content of the submission


3, Get way to transfer the amount of data is very small, generally limited to about 2 KB, but the execution efficiency is better than the Post method, and the post way to pass a relatively large amount of data , it is waiting for the server to read the data, but there is also a byte limit, this is to avoid malicious attacks on the server with a large amount of data, according to Microsoft, Microsoft to use Request.Form () can receive the maximum data limit, IIS 4 is a KB byte, IIS 5 is a KB word Section

Recommendation: Unless you are sure that your submitted data can be submitted at one time, otherwise, please use the Post method


4, get method to submit data, will bring security issues, such as a landing page, through the Get method to submit data, the user name and password will appear in the URL , if the page can be cached or someone else can access the client's machine, the user's account number and password can be obtained from the history, so the form submission suggests using the Post method; The common problem with the form page submitted by the Post method is that if the page refreshes, a dialog box pops up

Recommendation: For security reasons, it is recommended that you use Post to submit data

Post the difference between a and get GET the difference from Post is: (for CGI) if it is transferred in a Get mode, the parameter appended to the CGI program URL is passed directly to the server and can be read from the server side of the QUERY_STRING environment variable; if transferred by post, the parameters are packaged in the datagram and sent to the server, and can be read from the CONTENT_LENGTH environment variable. another situation is that you are using the Get method, but the parameters that are passed are the path, such as: ----< ahref= "/cgi-bin/a.pl/usr/local/bin/pine" >CGI< /A > ---- The parameter "/usr/local/bin/pine" that is passed is stored in the PATH_INFO environment variable. The environment variable is read in $str= $ENV {' query_string '}; theoretically, get is requesting data from the server, and post is sending data to the server. In fact, the Get method is to add a data parameter queue (query string) to a URL with a value corresponding to the form one by one. For example, Name=john. In the queue, values and tables are separated by A & symbol, space is replaced by a number, and special symbols are converted into 16-binary code. Because this queue is inside the URL, the parameters of the queue can be seen, recorded, or changed. Usually the Get method also restricts the size of the characters. In fact, the Post method can not time limit the delivery of data to the server, the user in the browser is not visible to the process, so the Post method is more suitable for sending a confidential (such as credit card number) or a large amount of data to the server. Post is to allow the transfer of large amounts of data, and the Get method will be transferred to the data attached to the URL, and then to the server together, so the amount of data transferred will be limited, but the efficiency is better than the Post method. for the data that gets submitted, the WWW server puts the data in the environment variable query_string, and for the Post method, the data is sent to the stdout of the WWW server, and then the CGI is read from its own stdin. Using traditional CGI methods, users must program themselves to process the data. GET The difference from post is that if it is transferred in a Get mode, the parameters attached to the CGI program's URL are passed directly to the server and can be read from the server side of the QUERY_STRING environment variable, and if it is transmitted by post, The parameters are packaged in the datagram and sent to the server, and can be read from the CONTENT_LENGTH environment variable. Another situation is that you are using the Get method, but the parameters that are passed are the path, such as:

----< ahref= "/cgi-bin/a.pl/usr/local/bin/pine" >CGI</A >

----the parameter "/usr/local/bin/pine" that is passed in this case is stored in the PATH_INFO environment variable. The environment variable is read in $str= $ENV {' query_string '};
To sum up: Get method: The URL string itself to pass data parameters, on the server side can be read from the ' query_string ' variable, high efficiency, but lack of security, also can not handle complex data (only string, such as in servlet/ JSP can not handle the use of Java, such as vector functions); Post mode: In terms of transmission mode parameters will be packaged in the datagram transmission, read from the environment variable content_length, easy to transfer the larger data, and because the data is not exposed in the browser address bar, the security is relatively high, but such processing efficiency will be affected. ------------------- GET and POST Differences in Requests
--TCP/IP
Detailed Agreement Volume 3
13.3.1 Message Type: Request and response
Http/1. There are two types of 0 messages: request and response. Http/1. 0 The format of the request is:
Reqe t-l i n E
Headers (0 or more)

Body (valid only for post requests)
request-l i n e The format is:
Request Request-uri HTTP Version number
the following three types of requests are supported:
1) G E T request to return any information that is indicated by the RE q u E s t-u R i.
2) an H e A D request, similar to a G E t request, but the server program returns only the header information for the specified document, not the actual document content. This request is often used to test the correctness, accessibility, and recent modification of hypertext links.
3) P O S T is requested to send an email, news or send a form that can be filled in by an interactive user. This is the only request that needs to send B o d y in the request. When using P O S t request, the message header c o n t e n t-l e n g t h field is required
Indicates the length of B o d y.
--TCP/IP protocol Detailed Volume 3

Got it? A GET request indicates that the client requests a URI, and the server returns the Uri,post request requested by the client indicating that the client is requesting the data as well as submitting the form, and the data to be submitted is placed in the body part of the request message. After the server receives such a request, it usually needs to process the data.
Ask this question when applying for the development of the Java EE. The point of asking questions is how the server handles the two requests differently than the two requests. Of course, as a JSP servlet developers generally you do not feel that two kinds of requests are different, because the Web server has processed these requests, the Web server calls the corresponding Jsp/servlet in response to the client request, for the POST request, The Web server has taken the data submitted by the client and added it to the request object. However, the Doget, Dopost method of the request servlet for GET, post is called by the response. That is, if the client sends a GET request, then you write to the servlet in the Dopost () method of the code is not executed, and if it is a POST request, written in doget () code is not called (for all manner of requests, The code written in Doservice is called, because the requests doget Dopost in the HttpServlet class are distributed by Doservice, specifically about the life cycle of the servlet.
HTTP Request: The difference between the Get and post methods

HTTP defines different ways to interact with the server, and the most basic method is GET and POST. In fact GET applies to most requests, while retaining POST is only used to update the site. According to the HTTP specification, get is used for information acquisition and should be secure and idempotent. The so-called security means that the operation is used to obtain information rather than modify information. In other words, GET requests generally should not have side effects. Idempotent means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it seems. Fundamentally, the goal is that when a user opens a link, she can be confident that the resource has not changed from its point of view. For example, the front page of news sites is constantly being updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent, as it always returns the current news. Vice versa. The POST request is not that easy. POST represents a request that might change resources on the server. Still take the news site as an example, the reader's comments on the article should be implemented through a POST request, because the site is different after the comment is submitted (for example, a note appears below the article);
When the form is submitted, if you do not specify method, the default is a GET request, and the data submitted in the form will be appended to the URL, separated from the URL. The alphanumeric characters are sent as-is, but the space is converted to the "" sign, and the other symbols are converted to%XX, where XX is the ASCII (or ISO Latin-1) value that the symbol represents in 16 binary notation. The GET request submits the data to be placed in the HTTP request protocol header, and the data submitted by the post is placed in the Entity data;
The Get method submits only 1024 bytes of data, while Post does not have this limit.
Get different from the Post method In the B/s application, the foreground and background data interaction is done through the form form in HTML. The form provides two ways to transmit data--get and post. Although they are all methods of data submission, they are quite different in actual transmission and can have a serious impact on the data. Although the Web container has shielded some of the differences for the convenience of getting variable values, it is also helpful to understand the differences between the two in future programming.
? The Get and post methods in the form, respectively, correspond to the Get and post methods in the HTTP protocol during data transfer. The main differences are as follows:
? 1, get is used to obtain data from the server, and post is used to pass data to the server.
? 2. Get adds the data in the form in the form of Variable=value, followed by the URL to which the action points, and both use "?". connections, and each variable is connected by a "&" connection; Post is the data in the form that is placed in the data body of the forms, in the same way that the variables and values are passed to the URL that the action points to.
? 3, get is not safe, because in the transmission process, the data is placed in the requested URL, and now many existing servers, proxy servers or user agents will log the request URL to the journal file, and then put in a place, so that there may be some privacy information to be seen by third parties. In addition, users can see the submitted data directly in the browser, and some system internal messages will be displayed in front of the user. All the actions of the post are not visible to the user.
? 4, get transmission of small amount of data, mainly because of the URL length limit, and post can transfer a large amount of data, so the upload file can only use post (of course, there is a reason, will be mentioned later).
? 5. Get restricts the value of the data set for form forms to be ASCII characters, while Post supports the entire ISO10646 character set.
? 6, get is the default method for form.
? GET and the data format of the POST are the same:
The maximum byte limit for GET support is 2048 Bytes
The maximum byte limit for POST support is 2GB
use in Forms "POST" and the "Get" What's the difference?
In the form, you can use post or get. They are all legal values of method. However, the post and get methods are at least two points different on use:
1. The Get method passes the user's input through a URL request. The Post method is in another form.
2, get mode of submission you need to use Request.QueryString to get the value of the variable, and when the post is submitted, you have to access the submitted content through Request.Form.

Study the following code carefully. You can run it to feel:

Code
<!--two form only the method property is different--
<form action= "getpost.asp" method= "Get" >
<input type= "text" name= "text" value= "Hello World" ></INPUT>
<input type= "Submit" value= "Method=get" ></INPUT>
</FORM>
<BR>
<form action= "getpost.asp" method= "POST" >
<input type= "text" name= "text" value= "Hello World" ></INPUT>
<input type= "Submit" value= "Method=post" ></INPUT>
</FORM>

<BR>
<BR>

<% If request.querystring ("Text") <> "then%>
The string passed through the Get method is: "<b><%= request.querystring (" Text ")%></b>" <BR>
<% End If%>

<% If Request.Form ("Text") <> "then%>
The string passed through the Post method is: "<b><%= request.form (" Text ")%></b>" <BR>
<% End If%>

Description
Save the above code as getpost.asp, then run, first test the Post method, at this time, the browser URL does not change anything, the result is returned:
The string passed through the Post method is: "Hello World"
Then the test is submitted with the Get method, note that the URL of the browser becomes:
Http://localhost/general/form/getpost.asp?Text=Hello+World
The result of the return is:
The string passed by the Get method is: "Hello World"
Finally, through the Post method submission, the browser URL is:
Http://localhost/general/form/getpost.asp?Text=Hello+World
And the returned result becomes:
The string passed by the Get method is: "Hello World"
The string passed through the Post method is: "Hello World"

Tips
Submitting data through the Get method can pose a security issue. such as a landing page. When data is submitted through the Get method, the user name and password appear on the URL. If:
1, the landing page can be cached by the browser;
2, other people can access the customer's machine.
Then someone can read the account number and password from the browser's history. Therefore, in some cases, the Get method poses a serious security problem.
Suggestions
The Post method is recommended for use in form.

The difference between get and post

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.