0

I need to post data to a url and redirect to the same. Presently i am using the code:

using (WebClient client = new WebClient())
{
    byte[] response =
    client.UploadValues("https://website.com/target.aspx", new NameValueCollection()
    {
        { "param1", 1 },
        { "param2", 0 }
    });

    string result = System.Text.Encoding.UTF8.GetString(response);
}

I am getting html string as response. I need to redirect to the page "https://website.com/target.aspx".

Grant Winney
  • 65,241
  • 13
  • 115
  • 165

1 Answers1

0

You cannot redirect using post, but instead you can make a normal get redirect Response.Redirect("https://website.com/target.aspx?s=1"); with the query param s=1 (submit true). Now when the target.aspx page opens you may use javascript to check the query parameters and if the s param is 1 you use document.getElementById("idofyourform").submibt(); this will post the form.

In addition if you want also to fill the form values you may add other parameters to your query string. They will get read and used to fill the form data in the page you redirect (target page). Then you check the s variable (or any other whatever you name it) and do the automatic post!

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39