Response.Redirect which POSTs data to another URL in ASP.NET

Xaqron picture Xaqron · May 19, 2011 · Viewed 42.7k times · Source

I want to redirect a response to another URL while it contains some POST data in it's HTTP header.

// Inside an ASP.NET page code behind:
Response.Redirect("http://www.example.com/?data=sent%20via%20GET");
// This will sent data to http://www.example.com via GET.
// I want to POST this data to http://www.example.com instead.

How to do this in ASP.NET?

Answer

Govind Malviya picture Govind Malviya · May 19, 2011

you can send huge data also with this trick..

Response.Clear();

StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>",postbackUrl);
sb.AppendFormat("<input type='hidden' name='id' value='{0}'>", id);
// Other params go here
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");

Response.Write(sb.ToString());

Response.End();