Introduction
When you want to transfer data from one web server to another web server through an ASP.NET application, then you can use the POST method to do the same.
The POST method is used to request that the origin server accepts the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.
Background
Responses to this method (POST method) are not cacheable, unless the response includes the appropriate Cache-Control or Expires header fields. However, the 303 response can be used to direct the user agent to retrieve a cacheable resource.
Using the code
Just call PostMe method and add the input parameters to it:
void PostMe(string LoginName, string Password, string isChecked)
{
RemotePost myremotepost = new RemotePost();
myremotepost.Url = "Default2.aspx";
myremotepost.Add("field1", LoginName);
myremotepost.Add("field2", Password);
myremotepost.Add("field3", isChecked.ToString());
myremotepost.Post();
Session["logoutStatus"] = null;
}
public class RemotePost
{
private System.Collections.Specialized.NameValueCollection Inputs =
new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name, string value)
{
Inputs.Add(name, value);
}
public void Post()
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write(string.Format(
"</head><body onload=\"document.{0}.submit()\">", FormName));
System.Web.HttpContext.Current.Response.Write(string.Format(
"<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >",
FormName, Method, Url));
for (int i = 0; i < Inputs.Keys.Count; i++)
{
System.Web.HttpContext.Current.Response.Write(string.Format(
"<input name=\"{0}\" type=\"hidden\" value=\"{1}\">",
Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
}
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();
}
}