I need to post to another url / server, however I need to add in other values before it goes to the other url / server. So I would like to post back to my own server, add in the values to the "post" then redirect to the new url.
I've done some searching and there are several answers about doing similar on stackoverflow. Including one particularly good one that I can't find anymore that gave 3 or 4 different examples. Post Method and Redirect With Some Values Without Form C# | Post Data To Url and Redirect | Post form data using HttpWebRequest
However they all seem to create a new set of values to post rather than retrieving the current set of post values and then adding to them. One of them indicated that I couldn't post using Response.Redirect(). So specifically ...
- How can I retrieve the current "post" and add my own values to it.
- How can I then send the user to another url with that posted data? I want the user to go to a different page after adding my own values on the server.
There's a chance this is a duplicate (with the magnitude of questions on stack it's quite possible) ... if someone can find the answers somewhere else please let me know. I'm working on code currently and will add that to the question the minute I have it ... later tonight.
Edit #1
public ActionResult Index(FormCollection form)
{
//string[] outGoingPostValues = new string[Request.Form.AllKeys.Length + 2];
string[] incomingPostValues = Request.Form.AllKeys;
foreach (string t in incomingPostValues)
{
Response.Write(t + ": " + Request.Form[t] + "<br>");
}
// add in two new keys
Response.Write("Value1: " + "value1" + "<br>");
Response.Write("Value2: " + "value2" + "<br>");
var url = "http://newURL.com";
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
return Redirect("http://someurl.com");
}
I'm currently trying to test it out by redirecting to my own view and trying to print out the following ...
@{
string[] outGoingPostValues = new string[Request.Form.AllKeys.Length + 2];
string[] incomingPostValues = Response. ?????
foreach (string key in incomingPostValues)
{
Html.Raw(key);
}
}