关于POST问题
今天在网上找了半天有关POST获取的问题,结果都是获取URL参数的,小弟想请各位高手帮忙,发个获取POST内容的例子,假设有一个页面Temp.html,页面代码如下:
HTML code
<form action="Default.aspx" method="post" target="_blank">
<input type="text" id="name" name="name" />
<input type="submit" id="SubMit" name="SubMit" />
</form>
当我点击按钮转向一个aspx页面,希望在这个页面里用C#的语法,获取到id为name的TextBox中的内容也就是他的value
------解决方案--------------------你要跳转到的就是Default.aspx吗?还是其它页面?
------解决方案--------------------有很多方法 Session也可以
private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
------解决方案--------------------string url = "网址";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string s = "要提交的数据";
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes (LoginInfo);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes,0,requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();
Response.Write(line);
sr.Close();
res.Close();
--------------------------------从网上找的,不知对你有没有帮助!!
------解决方案--------------------
剛才看錯了,你那個簡單的
string name = Request["name"]; //Request["控件的name屬性"]