jlp
jlp

Reputation: 10358

POST a HTML Form programmatically and display response

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.

Upvotes: 1

Views: 1105

Answers (3)

LoveMeSomeCode
LoveMeSomeCode

Reputation: 3937

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

Upvotes: 0

Greg B
Greg B

Reputation: 14888

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.

Upvotes: 0

liron
liron

Reputation: 385

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...)

Upvotes: 0

Related Questions