Go: The difference between get and post methods in an HTML form

Source: Internet
Author: User
Tags html form

1. Getis used to get data from the server, andPostis used to pass data to the server.
2,Getfollow the data in the formVariable=valuethe form, added to theActionThe point ofURLback, and both use"?"connection, and each variable is used between"&"connection;Postis to put the data in the formformIn the data body, by the variable and value corresponding to the way, passed to theActionthe pointURL.  
3,Getis unsafe because in the transfer process, the data is placed in the requestedURL, many of the existing servers, proxy servers, or user agents will now requestURLlog files and place them somewhere so that there may be some privacy information that is visible to 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. Postall operations are not visible to the user.  
4,GetThe amount of data transferred is small, mainly because theURLlength limit;Postcan transfer a large amount of data, so the upload file can only usePost(There is a reason, of course, that will be mentioned later).  
5,GetLimitFormThe value of the form's dataset must beASCIIcharacters;Postsupport the entireISO10646character Set. The default is to useiso-8859-1Coding 
6,Getis aFormthe default method.
The following comparisons are very very much used:
DoJavaof theWebDevelopment has a period of time, there is a problem is always bothering me, is garbled problem, is basically online search solution (online information is really a lot), are a lot of introduction how to solve this kind of garbled problem, but not a few of the context of the problem to say clearly, sometimes read some articles, think they understand, But in the development of garbled problems and like ghosts out of the scary, really big head! This article is my long time and garbled to fight some of the accumulation of understanding, but also hope that more friends to give guidance and supplement.  
Formhave a2method to submit the data to the server,Getand thePost,Say it separately.  
AGetSubmit 
1.First, the client (browser)formTable SingleGetThe method is to encode the data and submit it to the server side.  

forGetmethod, the data is concatenated in the requestedURLlater as parameters, such as:HTTP://LOCALHOST:8080/SERVLET?MSG=ABC
(A very common garbled problem is coming up, ifURLIf Chinese or other special characters are present, such as:http://localhost:8080/servlet?msg=Hangzhou, server-side easy to get garbled),URLOnce the stitching is complete, the browser willURLmakeURL encode, and then send it to the server,URL encodethe process is to put partURLAs a character, in a coded way (e.g.:UTF-8,GBKencoded into binary bytecode, and then each byte with a3characters of a string"%xy"said, whereXYis a two-bit hexadecimal representation of the byte. What I said here may not be clear, specific introduction can be seenJava.net.URLEncoderthe introduction of the class is here. Understand theURL encodethe process that we can see2a very important question, first: NeedURL encodecharacters are generally non-ASCIIcharacters (generally speaking), in general, except for English letters (such as: Chinese, Japanese, etc.) should be carried outURL encode, so for us, it's all English letters.URLdoes not appear the server get garbled problem, garbled isURLIt is caused by Chinese or special characters, and second:URL encodeHow do you encode characters in that way? This is the browser thing, and different browsers have different practices, the Chinese version of the browser will generally use the defaultGBK, you can also use it by setting the browserUTF-8, different users may have different browser settings, but also create different encoding methods, so many of the site's approach is to firstURLChinese or special characters in theJavaScriptdoURL encode, and then splicingURLsubmit data, that is, for the browser to doURL encode, the advantage is that the site can be unifiedGetmethod to encode the data that was submitted.  completed theURL encode, then now theURLit becameASCIIThe characters in the range, and then theiso-8859-1the encoding method is converted to binary with the request header sent out together. Here is to say a few more words, forGetmethod, there is no request entity, which contains the dataURLare in the request head, the reason whyURL encode, the reason for my personal feeling is that for the head of the request, the end is to useiso-8859-1Encoding is encoded into binary101010 .....The pure data is transmitted on the Internet, if it directly contains special characters such as Chineseiso-8859-1encoding loses information, so do it firstURL encodeis necessary.  
2. Server-side (Tomcat) is how the data is fetched to be decoded.  

The first step is to use the data firstiso-8859-1to decode, forGetmethod,Tomcatgetting the data isASCIIThe request header character within the range, where the requestURLwith parameter data, if the parameter has special characters such as Chinese, then the current is stillURL encodeafter the%xystate, stop first, let's start by referring to the process by which developers generally obtain data. Usually, we all are.request.getparameter ("name")to get the parameter data, weRequestthe object or data is decoded, and the decoding process is not specified in the program, here to say, there are a lot of beginners to userequest.setcharacterencoding ("Character Set")can specify the decoding method, in fact, it is not possible to seeservletthe officialAPIExplains how this method is interpreted:Overrides The name of the character encoding used in the body of this request. This method must is called prior to reading request parameters or reading input using Getreader ().can be seen forGetmethod He was powerless. So what encoding is the way to decode the data?TomcatThe default default isIso-8859-1,so we can find out why .Getrequest with Chinese parameter why on the server side get garbled, because the client is generally usedUTF-8orGBKto the dataURL encode, here withiso-8859-1WayURL Decoderobviously not, in the program we can directly 
JavaCode 
1. New String (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "Client-specifiedURL encodeEncoding Method") 
Restore the bytecode, and then decode the data in the correct way, the articles on the web are usuallyTomcatmake a configuration inside. 
XmlCode 
1. <connector port= "8080" protocol= "http/1.1" maxthreads= "" "connectiontimeout=" 20000 "redirectport=" 8443 " uriencoding= "GBK"/>
This is to letTomcatafter fetching the data in the specified wayURL Decoder,URL Decoderthe introduction here 
APostSubmit 
1.the client (browser)formTable SinglePostmethod is how the data is encoded and submitted to the server side.  
in thePostthe data to be transmitted in the method must also beURL encode, then what is his coding method?  
in theformwhere theHTMLIf there's a paragraph in the file<meta http-equiv= "Content-type" content= "text/html; charset=Character Set (GBK,Utf-8, etc.)"/>, thenPostwill be encoded using the encoding specified here. It is generally thought that this code is to let the browser know what character set to interpret the page, so the site will put it inHTMLcode The most front-end, try not to appear garbled, in fact, it also has a role is to specifyformform'sPostmethod to submit the dataURL encodeencoding method. From here we can see that forGetmethod to count, the browser to the dataURL encodeThe encoding method is determined by the browser settings (you can use theJSspecified), andPostmethods that developers can specify.  
2. Server-side (Tomcat) is how the data is fetched to be decoded.  
If you useTomcatdefault settings, and no encoding settings such as filters, then he also usesiso-8859-1Decoded, butrequest.setcharacterencoding ("Character Set")can be handy.  

I found out what it said.TomcatThe premise of doing this is not specifying the encoding in the request header, if the request header specifies the encoding method will be encoded in this way.  
have a2The address of the article is recommended, respectively 
LaymanURLCode:http://www.cnblogs.com/yencain/articles/1321386.html; 
Table SinglePostmethod When submitting data garbled problem:http://wanghuan8086.javaeye.com/blog/173869

UsePostIt's important toformwhere theHTMLIf there's a paragraph in the file<meta http-equiv= "Content-type" content= "text/html; charset=Character Set (GBK,Utf-8, etc.)"/>

Go: The difference between get and post methods in an HTML form

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.