How to redirect using POST, not with GET C #

I am using Redirect with the GET method, like this (works fine):

Response.Redirect(string.Format("../NewPage.aspx?Name1={0}&Name2={1}","name1", "name2" );

But I would like to use the POST method, so the client does not have access to these variables. I searched and found " Response.Redirect with POST instead of Get? "

I currently have the following code snippet as described:

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");

My question is, how can I use / get the passed variables in the NewPage.aspx page?

Thanks for any help.

0
source share
1 answer

In fact, you can redirect POST using the HTTP status code 307; and sometimes there are valid use cases, for example, in a banking application.

"307 ( HTTP/1.1): URI, URI. , 302 , . , POST POST". ()

.

, , ; , .

EDIT: , .

0

Source: https://habr.com/ru/post/1673767/


All Articles