GET request and POST request

Source: Internet
Author: User
Tags html header

The two most common HTTP requests on the web are get requests and post requests. During Java Web development, we always use the doget and dopost methods in servlet to process requests. More often, we call the dopost method in the implementation of the doget method. Even after nearly two years of web development, I still don't know much about basic concepts such as GET requests and post requests. I recently read "javascript advanced programming" (I haven't read it for a long time !), I reorganized the concepts of GET requests and post requests.

Get is the most common request type to obtain data from the server. Each time you enter a URL in the browser to open the page, a GET request is sent to the server. The GET request parameters are appended to the end of the URL with a question mark, followed by a name/value pair connected. For example, web site http://bt.neupioneer.com/viewthread.php? Tid = 87813, where TID is the parameter name and 87813 is the parameter value. In programming, the most frequently used get is the hyperlink list. Most of the parameters are concatenated from the fields read from the database. In Ajax, we often use get to extract the tag value of the page and construct a URL after splicing it into a string. Get is restricted in use, and the maximum URL length is 2 kb. Therefore, if the form contains a large text segment such as textarea, do not use get. For a form, get adds the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one. You can see the parameters passed in through the URL. Therefore, it is insecure compared to post.

Most scenarios of post are where forms are submitted, because post can send more data than get. In JavaScript advanced programming, a maximum of 2 GB can be sent, I don't quite believe this. Some articles on the Internet say that the maximum size of IIS4 is 80 KB, and that of iis5 is KB. I don't know the situation in Tomcat. Post uses the http post mechanism to place fields in the form and their content in the HTML header and send them to the URL address referred to by the Action attribute. Compared with get, post content is not displayed in the URL, which is somewhat safer. When I log on to a form like this, I only set the Request Method to post, so that the user name and password information are not displayed in the browser, but it is unclear that, whether there is a better way to encrypt password and other information (I do not know how to encrypt unknown requests if the request is not sent to the server, and a clear friend may wish to give a solution ). In Ajax, if you want to interact with the server, add request. setRequestHeader ("Content-Type", "application/X-WWW-urlencoded"); this script is mentioned in many Ajax textbooks. In addition, the passed parameters must be encoded. In JavaScript, the encoding function is encodeuricomponent (XX ).

GET request and POST request

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.