i want to redirect user to payment page in asp.net core with post method.
i did it in asp.net like this:
public void Post()
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write("<html><head>");
HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", m_FormName));
HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", m_FormName, m_Method, m_Url));
for (int i = 0; i < Inputs.Keys.Count; i++)
{
HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
}
HttpContext.Current.Response.Write("</form>");
HttpContext.Current.Response.Write("</body></html>");
}
should i use:
HttpContext.Response.WriteAsync
if yes how it work if so many line write by await.
is there any better way to do that?
What you're wanting to do is not possible. There is no way to make the client issue a POST. You can't make the client do anything. You can suggest that they request another URL (a redirect), but it's 100% up to the client whether or not to actually do that, and when and if the client does, it will be requested via GET only.
The only way to start a flow like this is to present the user with an HTML form with a submit button and an action of where you want them to go to begin the flow. It is then on the client to click that button.