• [转]GET和POST请求方式的异同


     

    基于web的页面请求有两种方式,他们分别是GETPOST方式.

    他们之间有很多的异同:

    1、采用post方式传输数据时,不需要在URL中显示出来,get方式要在URL当中进行显示(不安全性).

    2post方式的传输数据量较大,理论上来说是没有限制的,get方式由于受到UEL长度的限制,只能传递GET方式提交的数据最多只能有1024字节.

    3post顾名思义,就是为了将数据传送到服务器端,Get就是为了从服务器端取得数据.Get之所以也能传送数据,只是用来设计告诉服务器,你到底需要什么样的数据.post的信息作为http请求的内容,而Get是在Http头部传输的。

    我们的form表单的method方法,post,get.它在页面传值的时候的区别也就是上面提到的三点.

    先来看一下post方法.

    1.PostApply.aspx(发送页)

    页面前台代码:

    <form id="form2" method="post" action="PostRecive.aspx" runat="server">

        <asp:textbox id="postParmar" runat="server" text="中华人民共和国"></asp:textbox>

        <asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" />

    </form>

    后台代码:

    protected void Button1_Click(object sender, EventArgs e)

     {

             Server.Transfer("PostRecive.aspx");

     }

    2.PostRecive.aspx(接收页)

    后台代码:

     string parameter1=Request.Form["postParmar"].ToString();

     

    通过Session传递参数,在一个页面中赋值,在其他页面中共享,这个方式也被广泛应用.

    Session["para"]="中华人民共和国";//建立Session变量

    string parameter=Session["para"];//使用

     

    3.通过Context传值

    在传送页面之前,将需要传递到其他页面的值存在Context中。示例代码如下:

    传送页面

    protected void Button1_Click(object sender, EventArgs e)

        {

            Context.Items["para"] = postParmar.Text;

            Server.Transfer("PostRecive.aspx");

        }

     

    接收页面

    string parameter=Context.Items["para"].ToString();

     

    4.通过Server.Transfer的方式。

    这个方式在方法三种已经用到了,不过可以在调用页面为要传递到被调用页面的值创建属性(当然可以直接将它设成public),这样就可以在其他页面访问了。

    传送页面

     

    以上就是Post的在不同页面传递数据的方式了。

    下面是get方法

    //发送

    string url = "PostRecive.aspx?parameter1=" + postParmar.Text;

    Response.Redirect(url, false);

    //接收

    string parameter=Request.QueryString["parameter1"].ToString();

  • 相关阅读:
    firefox远程调试
    PHP使用unset销毁变量并释放内存(转)
    去掉超级链接的虚线框
    如何减少 reflow(回流)和 repaint(重绘)
    Chrome远程调试
    3大mobile浏览器远程调试
    IE6下使用滤镜后链接无法点击的BUG
    让IE6区块元素具备display:inlineblock属性
    Call to undefined function curl_init()解决方法(转)
    CSS3 Gradient
  • 原文地址:https://www.cnblogs.com/gsk99/p/1286663.html
Copyright © 2020-2023  润新知