Asp.net-Post & get-

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_5a8b8eb80100j7hv.html

Http://www.cnblogs.com/zhangmengjie/archive/2012/03/13/2394290.html
Thanks to the two great gods

 

1. Get is to get data from the server, and post is to send data to the server.
2.
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 and can be seen in the URL. Post is implemented through HTTP
Post mechanism to place fields and content in the form in HTML
The header is sent together to the URL address referred to by the Action attribute. You cannot see this process.
3.
For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.

4.
The data size transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default. Theoretically, the maximum size of IIS4 is 80 KB, and that of iis5 is 100kb.

5. Low get security and high post security. However, the execution efficiency is better than the POST method.

Suggestion:
1. The get method is more secure than the POST method. If it contains confidential information, we recommend that you use the post data submission method;
2. We recommend that you use the get method when querying data. We recommend that you use the POST method when adding, modifying, or deleting data;

 

 

 

1. Differences:
In form, you can use post or get. They are all valid values of method. However, the post and get methods have at least the following differences:

1The get method transmits user input through URL requests. The parameter and value passed by the get method are used on the URL? Name = Value & name = value. The post method is in another form.

2. submitting data using the get method may cause security issues. For example, a login page. When you submit data using the get method, the user name and password will appear on the URL. If the login page can be cached by the browser or accessed by others.
Then, others can read the customer's account and password from the browser's history. Therefore, in some cases, the get method may cause serious security problems.

3. Obviously, the get method has the limitation that it is inconvenient to transmit many values. Otherwise, the URL may exceed the length and cause an error.
 
There are two request methods: Post and get.
If they explore their differences in principle and involve the details of the HTTP transmission protocol, then Cheng Hua will do something for others. If you have time, please consult Huawei experts, I don't have to spend so much time working on enterprise software, so let's take a look.
Everyone knows the following differences:
1. When the post object transmits data, it does not need to be displayed in the URL, but the get method must be displayed in the URL.
2. The size of post data transmission can reach 2 MB. The get method is limited by the URL Length and can only transmit about 1024 bytes.
3. post, as its name implies, is to transfer data to the server segment, and get is to get data from the server segment. the reason why get can also transmit data is to design and tell the server what data you actually need. the post information is used as the content of the HTTP request, while get is transmitted in the HTTP header.
There are two methods for Form: Post and get. The difference between the method and the method in page value passing is the three points mentioned above.
Let's take a look at the POST method.
This method should have a lot of dealings with programmers in the ASP era, because there was no current viewstate at that time, and every page should post the page to itself to restore the original state, and then take a value one by one, assign a value again. now all these trivial things make viewstate work. so the actions that post the page to itself,
To some extent, it has been forgotten by Asp.net programmers, so the post is ignored by most of them. This is a double-edged sword of technological progress. It brings convenience while keeping your eyes open.
Viewstate must be included in the <form runat = "server"> form. If the form contains the "runat =" server "", the viewstate will be post to other pages, why? The old guy said, My viewstate is to save the current page status, you want to go to other pages, he said, no, ** unknown parameters. what if I want to post a form? There are four options.
1. create a new form on the page. Do not add the runat = "server" flag. Of course, the controls in this form do not need to use viewstate to pass values. when a button event in another form with runat = "server", manually call the submit () function of the new form.

Request object -- & Post & get page value transfer

Three pages in total: main1.aspx, get. aspx, and post. aspx

1. Post. aspx (only HTML code)

<Form ID = "form1" Action = "Main. aspx" method = "Post">

<Div> <input id = "text1" type = "text" name = "T1"/> <br/>

<Input id = "text2" type = "text" name = "T2"/> <br/>

<Input id = "button1" type = "button" value = "button"

Onclick = "Return button1_onclick ()"/> <br/>

 2. main1.aspx

Protected void page_load (Object sender, eventargs E)

{// POST method

String username = request. querystring ["name"]. tostring ();

String Pwd = request. querystring ["pass"]. tostring ();

Response. Write ("<font size = 18> welcome" + username + ", password:" + PWD + "</font> ");

 

// Get method // string username = request. Form ["T1"]. tostring ();

// String Pwd = request. Form ["T2"]. tostring ();

// Response. Write ("<font size = 18> welcome" + username + ", password:" + PWD + "</font> ");

 3. Get. aspx

Protected void button#click (Object sender, eventargs E)

{Response. Redirect ("Main. aspx? Name = "+ this. textbox1.text +" & pass = "+ this. textbox2.text );}

Summary:

1. Page value passing Method

<1>. Use form to pass data/post (HTML code is written );

Syntax for obtaining the field value of a form: request. Form ["Control name attribute"]; can be omitted as request ["Control name attribute"];

Note the following before using the POST method:

1. The form cannot run on the server. To remove runat = server, you must add the action attribute in the <form> tag and set the method attribute in the tag to post;

2: HTML controls must be used for controls.

3: the page for obtaining the value only recognizes the name attribute of the control. Therefore, you must add the name attribute to the control.

<2>. Use the URL-based value transfer/get method (write C # code)

Request. querystring ["field name"];

Considerations when using get:

1: "?" The link to the URL is divided into two parts, the first half is the URL, and the second half is the passed string (a combination of variable names and values)

2: If you want to pass multiple values, separate these key values "&"

2. Differences between the post and get methods:

<1>. Get transmits data through URL requests, and the data is directly displayed on the URL. Post uses the httppost mechanism and its content is in the header, which is invisible to users during processing.

<2>. Get is used to obtain data from the server, and post is used to transmit data to the server.

<3>. The data volume transmitted by get is small, and the size is limited to around 2 kb. The post transmission volume is relatively large, but there are also byte restrictions.

<4>. The get security is low, and the post security is high, but the execution efficiency is high.

Request object -- & Post & get page value transfer

Three pages in total: main1.aspx, get. aspx, and post. aspx

1. Post. aspx (only HTML code)

<Form ID = "form1" Action = "Main. aspx" method = "Post">

<Div> <input id = "text1" type = "text" name = "T1"/> <br/>

<Input id = "text2" type = "text" name = "T2"/> <br/>

<Input id = "button1" type = "button" value = "button"

Onclick = "Return button1_onclick ()"/> <br/>

 2. main1.aspx

Protected void page_load (Object sender, eventargs E)

{// POST method

String username = request. querystring ["name"]. tostring ();

String Pwd = request. querystring ["pass"]. tostring ();

Response. Write ("<font size = 18> welcome" + username + ", password:" + PWD + "</font> ");

 

// Get method // string username = request. Form ["T1"]. tostring ();

// String Pwd = request. Form ["T2"]. tostring ();

// Response. Write ("<font size = 18> welcome" + username + ", password:" + PWD + "</font> ");

 3. Get. aspx

Protected void button#click (Object sender, eventargs E)

{Response. Redirect ("Main. aspx? Name = "+ this. textbox1.text +" & pass = "+ this. textbox2.text );}

Summary:

1. Page value passing Method

<1>. Use form to pass data/post (HTML code is written );

Syntax for obtaining the field value of a form: request. Form ["Control name attribute"]; can be omitted as request ["Control name attribute"];

Note the following before using the POST method:

1. The form cannot run on the server. To remove runat = server, you must add the action attribute in the <form> tag and set the method attribute in the tag to post;

2: HTML controls must be used for controls.

3: the page for obtaining the value only recognizes the name attribute of the control. Therefore, you must add the name attribute to the control.

<2>. Use the URL-based value transfer/get method (write C # code)

Request. querystring ["field name"];

Considerations when using get:

1: "?" The link to the URL is divided into two parts, the first half is the URL, and the second half is the passed string (a combination of variable names and values)

2: If you want to pass multiple values, separate these key values "&"

2. Differences between the post and get methods:

<1>. Get transmits data through URL requests, and the data is directly displayed on the URL. Post uses the httppost mechanism and its content is in the header, which is invisible to users during processing.

<2>. Get is used to obtain data from the server, and post is used to transmit data to the server.

<3>. The data volume transmitted by get is small, and the size is limited to around 2 kb. The post transmission volume is relatively large, but there are also byte restrictions.

<4>. The get security is low, and the post security is high, but the execution efficiency is high.

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.