A brief analysis of two submission methods: ASP. NET Get and Post

  • 2020-05-27 04:44:47
  • OfStack


< form id="form1" method="get" runat="server">

       < div>   Name a word < asp:TextBox ID="name" runat="server">< /asp:TextBox>< br />  

                   Your web site < asp:TextBox ID="website" runat="server">< /asp:TextBox>< br />

                   < asp:Button ID="Button1" runat="server" Text="send" />< br />

                   learning request  and  response The use of the < br />

   < /div>

 </form>

 < form id="form2" method="post" runat="server">

       < div>   Name a word < asp:TextBox ID="name2" runat="server">< /asp:TextBox>< br />  

                   Your web site < asp:TextBox ID="website2" runat="server">< /asp:TextBox>< br />

                   < asp:Button ID="Button2" runat="server" Text="send" />< br />

                   learning request  and  response The use of the < br />

     < br />

 </form>

The difference between ASP.NET Get and Post can be seen in URL.

The first is to receive data transmitted using the get method:


 protected void Page_Load(object sender, EventArgs e)

       {

           string id = Request.QueryString["name"];

           string website = Request.QueryString["website"];

           Response.Write(id + "< br>" + website);

          Response.Write(" You're using " + Request.RequestType + " Mode data transfer ");

       }

The second way is to write the data transmitted by the post method:


protected void Page_Load(object sender, EventArgs e)

       {

           string id2 = Request.Form["name2"];

           string website2 = Request.Form["website2"];

           Response.Write(id2 + "< br>" + website2);

           Response.Write(" You're using " + Request.RequestType + " Mode data transfer ");

     }

Third, the code that accepts both get and post methods to send data :A


  string id3 = Request.Params["name3"];
  string website3 = Request.Params["website3"];
  Response.Write(id3 + "< br>" + website3);

B writing


   string id3 = Request.Params["name3"];
   string website3 = Request.Params["website3"];
   Response.Write(id3 + "< br>" + website3);

B writing

   string id4 = Request["name4"];
   string website4 = Request["website4"];
   Response.Write(id4 + "< br>" + website4);

In form submission, the differences between ASP.NET's Get and Post approaches are summarized as follows:

The & # 8226; get gets data from the server, and post sends data to the server.

get is a parameter data queue added to URL referred to by the ACTION property of the submitted form. The value corresponds to each field 11 in the form and can be seen in URL. post is via HTTP post mechanism, which places each field in the form and its content within HTML HEADER and sends them to the URL address referred to by the ACTION attribute. Users can't see the process.

For get, the server USES Request.QueryString to get the value of the variable, and for post, the server USES Request.Form to get the submitted data.

The amount of data transmitted by get is small and cannot be greater than 2KB. post transfers a large amount of data and 1 is generally considered unrestricted by default.

get has very low security and post has high security. But the efficiency of the implementation is better than the Post method

Advice:

The security of get is worse than that of Post. If it contains confidential information, it is recommended to use Post to submit data.

When making data query, it is recommended to use Get; When adding, modifying or deleting data, Post is recommended

Wake up every morning is not the alarm clock, I want!


Related articles: