ispiro
ispiro

Reputation: 27713

How do I redirect with WebRequest?

I created a WebRequest to POST information. My objective is to emulate in C# a PayPal "buy now" button which is in html.

How do I get the redirect when sending the WebRequest? Simply having Response.Redirect doesn't work because I have to have the redirect with the information.

The code of the button I'm trying to emulate is:

<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
...
</form>

Upvotes: 0

Views: 294

Answers (2)

Aristos
Aristos

Reputation: 66639

You can not do redirect with post.

What you can do: Make the actually post direct to the paypal, or redirect to a second page that re-create all the post data, and make automatic post with javascript.

An example of how to create a page with parameters that make automatic post.

http://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET

Upvotes: 1

CyberDude
CyberDude

Reputation: 8989

Not sure you can do what you want from code behind. I had a similar situation where I had the form like yours besides the normal ASP.net form. I hid the non-ASP.net form through CSS so it's not in the user's face and then I triggered the POST via javascript (I put a button inside the form and then called buttonX.click(); )

Upvotes: 1

Related Questions