我很擅长C#,但我还没有用过ASP.NET,我想把一个参数传递给一个页面,页面会把它打印给用户。我在应用程序中执行以下操作来传递POST类型的参数
WebRequest request = WebRequest.Create("http://www.website.com/page.aspx");
request.Method = "POST";
string post_data = "id=123&base=data";
byte[] array = Encoding.UTF8.GetBytes(post_data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = array.Length;
既然我已经传递了参数,我如何从我的页面访问它们呢?另外,我上面的方法对于asp.net发布是正确的吗?我用PHP试过了,它工作得很好。
发布于 2012-06-20 01:35:14
在aspx页面的代码隐藏中,只需编写
string id = Request.Form["id"].ToString();
如果它是发布的数据,并且
string id = Request.Querystring["id"].ToString();
如果数据在URL中
发布于 2012-06-20 01:42:57
要发布数据,请执行以下操作:
var request = (HttpWebRequest) WebRequest.Create("http://www.website.com/page.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var postData = Encoding.UTF8.GetBytes("id=123&base=data");
request.ContentLength = postData.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(postData, 0, postData.Length);
}
要读取ASP.NET项目上发布的数据,请执行以下操作:
var id = Int32.Parse(Request.Form["id"]);
var data = Request.Form["base"];
https://stackoverflow.com/questions/11106217
复制相似问题