So as the title suggest how does one perform an HTTP POST to an external website while also redirecting the user there? I am looking for something similar to this:
Redirect("MyWebsite.com", HttpAction.POST, new RedirectData(new { item = "itemValue"}));
It has to be done in ASP.NET mvc.
EDIT
This behaviour is necessary to implement authentication on an external website. The algorithm for the authentication:
- User navigates to the webpage that requires him to be identified.
- The webpage calls the web service of the authentication website and initializes authentication.
- Initialization returns GUID that has to be posted to the given URL (let's say it is "MyWebsite.com").
- The user is supposed to be redirected to the URL that data was posted to.
So far I've managed to come up with this:
string url = "MyWebsite.com";
NameValueCollection formData = new NameValueCollection();
formData["ticket"] = Ticket.ticket;
WebClient webClient = new WebClient();
byte[] responseBytes = webClient.UploadValues(url, "POST", formData);
Response.BinaryWrite(responseBytes);
Response.Redirect("MyWebsite.com", true);
The response I get is the HTML of the website I am supposed to be redirected to and the question is - what now? How do I tell the browser to display HTML that I got via the response? If I simply redirect to "MyWebSite.com" it would execute a GET action, which is not what I am looking for. Doing binary write of the response accomplishes nothing - it just writes the response of the POST action to the action I am currently executing - there is no redirect to "MyWebSite.com".