我正在使用像这样的GET方法的Redirect(工作正常):
Response.Redirect(string.Format("../NewPage.aspx?Name1={0}&Name2={1}","name1", "name2" );
但我想使用POST方法,因此客户端无法访问这些变量。我搜索并找到了#34; Response.Redirect with POST instead of Get?"
目前,我有以下代码:
StringBuilder postData = new StringBuilder();
postData.Append("Name1=" + HttpUtility.UrlEncode("Name1") + "&");
postData.Append("Name2=" + HttpUtility.UrlEncode("Name2"));
//ETC for all Form Elements
// Now to Send Data.
StreamWriter writer = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.ToString().Length;
try
{
writer = new StreamWriter(request.GetRequestStream());
writer.Write(postData.ToString());
}
finally
{
if (writer != null)
writer.Close();
}
Response.Redirect("~/NewPage.aspx");
我的问题是,如何在NewPage.aspx页面中使用/获取传递的变量?
感谢您的帮助。