开发者

ASP.Net Creating Server Side Posting to external website with redirect

开发者 https://www.devze.com 2022-12-20 20:44 出处:网络
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

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 开发者_StackOverflow中文版don't want to post the entire form as this button event is called within a repeater


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.


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


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.


Jquery is life saving in this situation. Used for one of my project and works like a charm. Give it a try : Peter Finch - Using Javascript to POST data between pages

0

精彩评论

暂无评论...
验证码 换一张
取 消