以前GET和POST的提交方式一直都没弄懂,这回做了个例子了,分了两种方式来做。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string aa= Request.QueryString["aa"];//接受以GET方式提交过来的aa变量的值
string bb=Request.QueryString["bb"];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//string aa = Request.Form["aa"]; //以POST方式提交的接收
//string bb = Request.Form["bb"];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//Request.Params["aa"];//当不知道是用哪两种方式提交的时候 用这两种都可以
//Request.Params["bb"];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//Request["aa"];
//Request["bb"];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
protected void Button1_Click(object sender, EventArgs e)
{//获取服务器环境变量
Response.Write("当前网页的虚拟路径是:"+Request.ServerVariables["url"]);
Response.Write("<br>当前网页的虚拟路径是:"+Request.RawUrl);
Response.Write("<br>实际路径是:"+Request.ServerVariables["path_translated"]);
Response.Write("<br>实际路径是:"+Request.PhysicalPath);
Response.Write("<br>服务器名为:"+Request.ServerVariables["server_name"]);
Response.Write("<br>服务器IP为:"+Request.UserHostAddress);
}
protected void Button2_Click(object sender, EventArgs e)
{//获取客户端信息
Response.Write("这个客户端是否支持背景音乐:"+Request.Browser.BackgroundSounds);
Response.Write("<br>这个客户端是否支持COOKIE:"+Request.Browser.Cookies);
Response.Write("<br>这个客户端是否支持框架:"+Request.Browser.Frames);
Response.Write("<br>使用的是什么系统:" + Request.Browser.Platform);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
protected void Button3_Click(object sender, EventArgs e)
{//写入COOKIE
HttpCookie ck = new HttpCookie("mgod");
ck.Values["name"] = "张恒玮";
ck.Values["age"] = "21";
ck.Values["sex"] = "男";
Response.Cookies.Add(ck);
Response.Write("成功写入");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
protected void Button4_Click(object sender, EventArgs e)
{//读取COOKIE
HttpCookie getck = Request.Cookies["mgod"];
Response.Write(getck.Values["name"]);
Response.Write("<br>年龄是:" + getck.Values["age"]);
Response.Write("<br>性别是:" + getck.Values["sex"]);
}
}
点此下载练习代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
点此下载练习代码