What is the difference between form submission methods post and get?

Source: Internet
Author: User
Tags servervariables
What is the difference between form submission methods post and get?
Solution :
The difference between the two can be seen only after the form is submitted, mainly in the data transmission mode and receiving mode.
Procedure :
Both post and get are optional values of the form attribute method. The default value of method is get. The main differences between the two are:
1. on the client side, the get method submits data through the URL, as shown in address 1.4.3 in the address bar after submission.

Figure 1.4.3 address bar after the form is submitted in get Mode

The Location Bar remains unchanged after post is submitted, as shown in 1.4.4.

Figure 1.4.4 the address bar remains unchanged after the form is submitted in post mode.

2. on the server side, only request. querystring can be used to obtain data submitted in get mode. data submitted in post mode can only be obtained using request. Form:

<% @ Language = "VBScript" codePage = "936" %>
<HTML>
<Head>
<Title> test the form submission method </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Form method = "Post" Action = "<% = request. servervariables (" script_name ") %>">
Submit data:
<Input name = "ostr" type = "text">
<Br>
Submission method:
<Select name = "select" onchange = "This. Form. method = This. Value">
<Option value = "Post" selected> post </option>
<Option value = "get"> Get </option>
</SELECT>
<Br>
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
<%
If request ("Submit") <> "then
Response. Write "data submitted through" & request. servervariables ("request_method") & "is :"
If request. servervariables ("request_method") = "get" then
Response. Write Request. querystring ("ostr ")
Else
Response. Write Request. Form ("ostr ")
End if
End if
%>
</Body>
</Html>

Note: although the two submission methods can use request ("ostr") to obtain the submitted dataProgramEfficiency is affected and is not recommended.
Note
Run this example through IISCode(Use http: // localhost/method. for more information about IIS installation and configuration, see Section 4. Enter the submitted data and select post to submit. The result shown in Figure 1.4.4 is displayed. Select get to submit, as shown in Figure 1.4.3. Note

In general, try to avoid using the get method to submit a form because it may cause security problems. For example, if you use the get method in the login form, the user name and password entered by the user will be exposed in the address bar. However, in the paging program, the get method is better than the POST method. Attribute explanation of the form used in this example (see Section 4 for ASP ):
Get adds the parameter to the address specified by the Action attribute and opens it as an anchor.
Post processes sent data through http 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.