Overview of ASP. NET HtmlForm Control Learning and difference between Post and Get

Source: Internet
Author: User
Tags html header

I. Preface

1. Understand HTTP (hypertext transport protocol) hypertext Transfer protocol

It is a communication protocol between distributed, collaborative, and hypermedia system applications. It is the basis for world wide web information exchange. It is implemented by uploading HTML documents from the web server to the web browser, for example:

HTTP works on the TCP protocol in the TCP/IP protocol system. We can introduce the TCP/IP protocol level model, such:

The HTTP request method is as follows::
(1). OPTIONS: return the HTTP request methods supported by the server for specific resources. You can also use the '*' request sent to the Web server to test the server's functionality.
(2). HEAD: Requests the server for the same response as the GET request, but the response body will not be returned. This method can obtain metadata contained in the Response Message Header without transmitting the entire response content.
(3). GET: send a request to a specific resource. Note: The GET method should not be used in operations that produce "Side effects", for example, in web app. One of the reasons is that GET may be randomly accessed by web spider.
(4). POST: Submit a Data Processing request to a specified resource (for example, submit a form or upload a file ). Data is contained in the request body. POST requests may result in creation of new resources and/or modification of existing resources.
(5). PUT: Upload the latest content to the specified resource location.
(6). DELETE: The Request server deletes the resource identified by Request-URI.
(7). TRACK: The request received by the echo server is mainly used for testing or diagnosis.

2. Principles of Form submission

Here is a summary of the experts.:

(1) When the form is submitted, the form content will be encapsulated by the browser as an HTTP request message, which contains the name attribute value and value attribute value of all form elements, in the form of name = value.

(2) After the HTTP Request is obtained by webserver, it will be parsed and encapsulated into a Request object. The Request object contains a set of Parameters to store all the form element name value pairs.

(3 ). each form element name-value pair is encapsulated into a Parameter, which is actually a Map, so you can use request in your Servlet. getParameter (name) gets its value.

Since we have made it very clear, we still need to clear what form relies on for submission. Here, the form tag has an important attribute: enctype, it sets the encoding method used to submit form data. There are three types:

(1). application/x-www-form-urlencoded: This is the default encoding method. data is processed using the Value method. [I am Fuzzy]
(2). multipart/form-data: Process form data in binary stream mode.
(3). text/plain: used when the form's action attribute value is in the form of mailto: URL. It is mostly used to send emails directly through the form.

2. HtmlForm controls

1. The HtmlForm control is used to control <form> elements. The main attributes are as follows::

Attribute Description
Action

URL, which defines where data is sent when a form is submitted. Note: This attribute is always set to the URL of the page!

Attributes Returns all attribute names and value pairs of the element.
Disabled Boolean value indicating whether to disable the control. The default value is false.
EncType The MIME type used to encode the form content.
Id The unique id of the control.
InnerHtml

Sets or returns the content between the start tag and end tag of the HTML element. Special characters are not automatically converted to HTML objects.

InnerText

Sets or returns all text between the start tag and end tag of the HTML element. Special characters are automatically converted to HTML objects.

Method The method in which the form transmits data to the server. Valid values are "post" and "get ". The default value is "post ".
Name The name of the form.
Runat Specifies that the control is a server control. Must be set to "server ".
Style Sets or returns the CSS attribute applied to the control.
TagName The tag name of the returned element.
Target The target window for loading the URL.
Visible Boolean value indicating whether the control is visible.

Method: Post/Get. The difference is that Get indicates that the browser uploads data to the Server and transmits the data immediately. The execution efficiency is fast, but the data volume cannot be too large; while Post indicates that the server captures data, although not so immediately, there is no limit on the amount of data that can be transferred.

Action: The page on which the data is to be submitted, that is, the URL to which the data is sent.

2. Differences between Post and Get:

Http://jb51.net/web/72554.html
Form provides two data transmission methods: get and post. Although they are all data submission methods, they are indeed quite different in actual transmission, and may have a serious impact on data. Although the Web Container has shielded some differences between the two for the convenience of obtaining variable values, it will be helpful to understand the differences between the two in future programming.

The get and post methods in Form correspond to the GET and POST methods in the HTTP protocol during data transmission. The main differences between the two are as follows:

1. Get is used to obtain data from the server, while Post is used to transmit data to the server.

2. Get adds the data in the form to the URL pointed to by action in the form of variable = value, and the two use "?" And each variable is connected by "&". Post puts the data in the form data body and passes the data to the URL indicated by the action according to the corresponding variables and values.

3. Get is insecure because data is stored in the request URL during transmission, nowadays, many existing servers, proxy servers, or user proxies record the request URL to a log file and place it in a certain place, so that some private information may be seen by a third party. In addition, you can directly view the submitted data in the browser. Some internal messages are displayed in front of the user. All Post operations are invisible to users.

4. Get transmission has a small amount of data, mainly because it is restricted by the URL length; while Post can transmit a large amount of data, so only Post can be used for uploading files (of course, there is another reason, as mentioned later ).

5. Get restricts that the dataset value of Form forms must be ASCII characters, while Post supports the entire iso000046 character set.

6. Get is the default Form method.

The data transmitted through Post can be correctly converted to Chinese by encoding, but the data transmitted by Get does not change. In future programs, we must pay attention to this point.

1, Get method through the URL request to pass the user's data, the form of each field name and its content, connected to a pair of strings, placed in the action property referred to by the program url, such as http://www.mdm.com/test.asp? Name = asd & password = sad, data will be directly displayed on the url, just as the user clicks a link; the Post method uses the HTTP post mechanism, place the field names and content in the form in the HTML header and send them to the server for processing by the program that can be referred to by the action attribute. The program will pass the standard input (stdin) to read and process the form data.

2. The Get method uses Request. QueryString to obtain the value of the variable. The Post method uses Request. Form to access the submitted content.

3. The size of data transmitted in Get mode is very small, generally around 2 KB, but the execution efficiency is better than that of Post method. The size of data transmitted in Post mode is relatively large, it is waiting for the server to read data, but there are also byte restrictions. This is to avoid malicious attacks on the server using a large amount of data. According to Microsoft, Microsoft uses Request. the maximum data size that Form () can receive is limited. In IIS 4, it is 80 KB, and in IIS 5, it is 100 KB. We recommend that you submit the data at one time unless you are sure that you can submit the data at a time, otherwise, use the Post method whenever possible.

4. If you submit data in Get mode, security issues may occur. For example, when you submit data in Get mode on a login page, the user name and password will appear on the URL, if the page can be cached or other users can access the customer's machine, the user's account and password can be obtained from the history. Therefore, the Post method is recommended for form submission; A common problem on the form page submitted by the Post method is that when the page is refreshed, a dialog box is displayed. We recommend that you use Post to submit data for security reasons.

After you understand the HTML form control of ASP. NET, you can easily understand the form variables obtained by ASP. NET upload control and Request. Furthermore, the difference between Get and Post is critical. during last year's interview, we were thrown back because this was not answered well, it seems that in the future, we still need to familiarize ourselves with the basic things and work hard to smoothly carry out the work for the future.

Related Article

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.