The difference between get and post in an HTML form

Source: Internet
Author: User

When a user enters information into an HTML form (HTML form) and submits it, there are two ways to transfer the information from the browser to the Web server (Web servers).

One way is through the URL, and the other is in the body of the HTTP Request.

In the previous method, we use HTML form method = "get" , the latter method we use in the HTML form method ="post" .

Examples are as follows:

<form action = "..." method = "Get" >
<from action = "..." method = "POST" >

The data of the Form can be obtained through the Get or post method, the main difference is in the following aspects:

Get
    • URL changes, displaying the Name/value value of the HTML Form parameter in the URL.
    • Only for HTML Form with a small number of parameters, because the URL length has a character limit and cannot be infinitely long.
    • Information that involves security, such as a user password, cannot be used because it is displayed on a URL and is not secure.
Post
    • The URL does not change, and the HTML Form data is not displayed in the URL.
    • The information submitted by Form does not have a length limit.
    • Security-related information, such as user passwords, should be post-based.

Let's see how get is submitting the Form data. Let's start by writing an HTML file as follows:

The HTML display interface is as follows:

When you enter the name in the form text box of the HTML file, such as "Jacky", then click OK button, the mouse will jump to get.php, in get.php will show as.

You can see the URL in the address bar of the browser is:

Http://localhost:8080/get.php?username=Jacky

Note get.php The following string ?username=Jacky , which is a pair of name/value data, preceded by a question mark.

If you change the form method = "post" , you will not see the Name/value data in the browser's address bar, but only:

http://localhost:8080/get.php

when using GET, a question mark is added before the first pair of name/value values ? , and each pair of name/value values are & separated . For example, there are three parameters in a form, as follows:

<form action = "u.php" method = "Get" >name: <input type= "text" name= "username"/>age: <input type= "text" Nam E= "Age"/>gender: <input type= "text" name= "Gender"/><input type = "Submit" value= "OK"/></form>

For example, you fill out the Jacky,age entry in the name entry 50,gender the male, and the URL after submission is displayed as:

http://localhost:8080/get.php? Username=jacky&age=50&Gender=male

The difference between get and post 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.