views:

521

answers:

1

Hello, 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!

A: 

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

James S
The code to POST the actual form collection object the same way I received it over to server 2.Trying your code now :)
Alex
Note that FormCollection only seems to work on POSTs.
James S