1

I need to prepare ASP.NET site with form, fill form in code behind and then submit form to external site.

For example: user open www.myshop.com/pay.aspx, he does not have to fill anything because I fill form values in code behind and then user is automatically redirected to external site www.onlinepayments.com (with form data sent in POST).

I am able to make it work with regular hidden form and javascript that submits form but I dont like this way (user can see html).

So I use WebRequest class in code behind like in this answer: How do you programmatically fill in a form and 'POST' a web page?

However in this answer Response is string (target site html). What can I do with this string? I want my user see target site (conent and URL) like it would happen with regular html POST.

Community
  • 1
  • 1
jlp
  • 9,800
  • 16
  • 53
  • 74
  • Have you spoken to your online payment provider? Some have a server to server API, and will give you a URL to redirect to; some will allow for the cart to be signed prior to submission. – Rowland Shaw Sep 07 '11 at 11:24
  • @Rowland Shaw - it does not matter - online payment is just an example – jlp Sep 07 '11 at 11:29
  • So you mean you want them to fill out a form on one aspx page, and then when they hit Submit, you send the form values to another aspx page? – LoveMeSomeCode Sep 07 '11 at 21:28
  • @LoveMeSomeCode - yes but I send them to external page (not aspx) and it works but exactly the way I want – jlp Sep 15 '11 at 12:42

3 Answers3

0

You receive the response html as string - you can do with it whatever you want (included render the html as is to your page, or you can custom the html before rendering it, etc...)

liron
  • 375
  • 2
  • 12
  • but then user will see my URL instead target site URL and their CSS paths might be relative etc. I want user to 'be' on that site as it happen with regular post (that browser make) – jlp Sep 07 '11 at 12:17
0

It depends how the target site works. If the resultant page is static you could simply Response.Redirect your user there after you have done the POST programatically. If the page is shown based on some session or cookie value you can't really redirect them there.

Greg B
  • 14,597
  • 18
  • 87
  • 141
0

Ok, in that case what you can do is change your FORM tag's action parameter. This will send a POST request to the other form with all the form variables in it. The new form will have dig out those POST variables and do what it needs with them

LoveMeSomeCode
  • 3,888
  • 8
  • 34
  • 48