tags:

views:

250

answers:

3

On a button click event I am required to POST to a page on an external website and redirect there. I get how to do this using a GET method

Reponse.Redirect("www.somesite.com?my=params&as=aget")

But how can I do this on as POST?

I don't want to post the entire form as this button event is called within a repeater

A: 

You can build up the request using WebClient, adding the appropriate headers.

Oded
+2  A: 

Depends.

If you want to post the exact input of a form you have on your site (that is, you just replicate a form the other site has), then just set the form's action to the URL you want to post to and the browser will do everything for you.

If however you want to post some values you generate on the server (perhaps based on the input from your form), I'm afraid it's not possible. You can't redirect using a POST. Redirect is GET by it's nature.

BUT you might be able to fake it by doing a POST (using something like System.Net.WebClient) and then a redirect (it depends on how the other site handles the GET - it might display the same thing that it did on the POST, or not).

One more option (for the second case) would be to to do an AJAX call to your server, which will compute the required values, then do the POST to the other server from Javascript.

ionut bizau
For the first case (post directly to another site), you also probably want to make sure that the form tag does not include runat="server".
Cylon Cat
JavaScript is probably the way to go in this case.
Zhaph - Ben Duguid
A: 

My inner forms don't contain the runat="server" attribute so I can do what I want. I do get this problem though ASP.Net First inner form in Server Form doesn’t POST.

Duncan