简体   繁体   中英

Post Data To Url and Redirect

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 ".

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM