zoukankan      html  css  js  c++  java
  • get与post请求

    1.post请求

    如果表单以Post方式提交过来的,接收时必须以Requert.Form来接收,并且表单元素必须有name属性,而Form指定的键的名称就是name属性的值

     1  <form method="get" action="Accept.ashx">
     2         用户名:<input type="text" name="txtName" value=" " /><br />
     3 
     4         密码:<input type="password" name="txtPwd"/><br />
     5        <input type="submit" value="提交"/>
     6     </form>
     7 
     8 //以下为Accept.ashx页面
     9  public void ProcessRequest(HttpContext context)
    10     {
    11         context.Response.ContentType = "text/plain";
    12         //如果表单以Post方式提交过来的,接收时必须以Requert.Form来接收,并且表单元素必须有name属性,而Form指定的键的名称就是name属性的值
    13         string userName = context.Request.Form["txtName"];
    14         string userPwd = context.Request.Form["txtPwd"];
    View Code

    get请求

    如果是get请求,那么接收的时候必须用QueryString

     1 <form method="get" action="Accept.ashx">
     2         用户名:<input type="text" name="txtName" value=" " /><br />
     3 
     4         密码:<input type="password" name="txtPwd"/><br />
     5        <input type="submit" value="提交"/>
     6 
     7       //以下是Accept.ashx界面
     8       //如果是get请求,那么接收的时候必须用QueryString
     9         string userName = context.Request.QueryString["txtName"];
    10         string userPwd = context.Request.QueryString["txtPwd"];
    11         context.Response.Write("用户名是" + userName + "密码是" + userPwd);
    12         
    13         
    View Code

    总结:

    1).如果是post请求方式,那么表单中的数据会放到请求报文体中,发送到服务器,如果以get方式进行请求那么表单中的数据会放到URL地址栏中发送到服务器(注意:元素必须有name属性)

    2).在服务端接收方式不一样,如果是post请求用Request.Form,如果是get请求用Request.QueryString;

    3).post请求比get请求安全,注册登录等表单用post提交。

    4).post请求发送的数据比get请求大。

    只能将表单元素的value值提交到服务端(span,div等不属于表单元素,所以无法提交),并且表单元素必须要加value属性

  • 相关阅读:
    【史上最全】DDoS防御产品服务合集
    DDoS攻击与防御的心得体会
    防范DDoS攻击的15个方法
    什么是DDoS攻击?
    蜜罐技术详解
    全年DDoS攻击分析|知道创宇云安全2018年度网络安全态势报告
    抗D十招:十个方法完美解决DDoS攻击防御难题
    DDOS 攻击的防范教程--转载自阮一峰的博客
    手把手教你查看网站遭受到的Web应用攻击类型
    mlbox ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
  • 原文地址:https://www.cnblogs.com/ggsdduzbl/p/4987435.html
Copyright © 2011-2022 走看看