Alex
Alex

Reputation: 77379

C# ASP.NET MVC: Easy way/sample to re-POST a form collection?

I wondered if there is an easy way (sample?) to re-POST an incoming form collection to a different server.

The reason: I have server 1 which has a form with a bunch of fields, but they actually need to be stored on server 2. I can't allow people access to server 2 though, so I need to ask for the input on server 1. I'd still like to keep my already done MVC controller actions (which originally assumed posting to server 2 directly)

Would appreciate a hint or sample code on how to do this!

Thank you!

Upvotes: 0

Views: 1227

Answers (1)

James S
James S

Reputation: 3374

What are you having problems with, exactly? Receiving the data on server 1? Putting it into a format server 2 can handle? The actual transfer? Or the code on server 2?

The easiest would be something like this:

public ActionResult Proxy(FormCollection form) {
    var client = new System.Net.WebClient();
    client.UploadValues("http://server2/post.php", form);
}

James

Upvotes: 1

Related Questions