POST data to external site

W

Wayne P.

I'm working on a shopping cart webapp and I need to perform a form POST of
data to a 3rd party site (a payment processor, StormPay).

I seem to be having problems doing this. I have an image button which when
clicked performs the data validation. After successful validation, I need
the browser to redirect to the payment processer with a form post. How can
I do this?

I have tried a few things, failed. Below were my most 'reasonable
attempts'.

1) Based on the example found at
http://authors.aspalliance.com/stevesmith/articles/netscrape2.asp, I used a
System.Net.WebRequest object, and did successfully POST the data to the
other site, however because the browser does not redirect here, the output
was not seen (other than in my result variable). This of course is not
usable behavior becuase the user needs to see and respond to the output from
the resulting posted data. If I can get the broser to move with the
request, then this is okay - but how?

2) Going back to basics, I thought maybe a response.write would work. Using
the following code failed, as all it did was write the raw code back to the
top of my aspx page.

Response.Write("<form name='StormPay'
action='https://www.stormpay.com/stormpay/handle_gen.php' method='POST'
>")
Response.Write("<input type='hidden' name='test_mode' value='1' >")
'Testing Flag
Response.Write("<input type='hidden' name='generic' value='1' >")
Response.Write("<input type='hidden' name='payee_email' value='" &
System.Configuration.ConfigurationSettings.AppSettings.Get("StormPayAccountE
mail") & "' >")
Response.Write("<input type='hidden' name='product_name' value='" &
strProduct_name & "' >")
Response.Write("<input type='hidden' name='return_URL' value='" &
System.Configuration.ConfigurationSettings.AppSettings.Get("ReturnURL") & "'
>")
Response.Write("<input type='hidden' name='cancel_URL' value='" &
System.Configuration.ConfigurationSettings.AppSettings.Get("CancelURL") & "'
>")
Response.Write("</form>")
Response.Write("<script>")
Response.Write("document.StormPay.submit();")
Response.Write("</script>")

Thanks for the insight,

Wayne P.
 
W

William F. Robertson, Jr.

The second method is the approach you should take. However, when you are
calling Response.Write, you are writing out a >.

That will show up in the browser as >, so it will be displayed as a '>'
on the screen. You should have something like this:

Response.Write( "<form name='StormPay' action=....>" );

See if that helps you out any. If that doesn't work, post your view source
of the page to make sure the form is rendered properly, etc.

HTH,

bill
 
J

Joerg Jooss

William said:
The second method is the approach you should take. However, when you
are calling Response.Write, you are writing out a &gt;.

Hardly. It's an ugly hack that relies on client-side scripting. Why not
simply stream the response received by WebClient to the page's reponse
stream?

Cheers,
 
W

William F. Robertson, Jr.

But atleast his second solution would work. You solution does not meet his
requirements. He wants the user to be able to respond from the externally
posted site. Using the response from the webclient will not work in this
situation.

You have the server post and get the response from the remote server. The
remote server sends this:

<form action="main.aspx" method="post">
....
</form>

Since the user is on http://server.com/order.aspx the form action is set to
"main.aspx". Since the user's browser will not see the domain change. When
the user responds to the page, it will try to post it to
http://server.com/main.aspx instead of
https://www.stormpay.com/stormpay/main.aspx.

He could, of course, read through the WebClient response stream and manually
adjust the form action attribute, but "simply streaming" the response from
the WebClient will not work.

It might be a "hack", but it is the only method that has been posted on this
thread that will work.

bill
 
J

Joerg Jooss

William said:
But atleast his second solution would work. You solution does not
meet his requirements. He wants the user to be able to respond from
the externally posted site. Using the response from the webclient
will not work in this situation.

I didn't read that from the original post. I read it again and still think
he just didn't know what to do with the response received by the 3rd party's
site.
You have the server post and get the response from the remote server.
The remote server sends this:

<form action="main.aspx" method="post">
...
</form>

Since the user is on http://server.com/order.aspx the form action is
set to "main.aspx". Since the user's browser will not see the domain
change. When the user responds to the page, it will try to post it to
http://server.com/main.aspx instead of
https://www.stormpay.com/stormpay/main.aspx.

He could, of course, read through the WebClient response stream and
manually adjust the form action attribute, but "simply streaming" the
response from the WebClient will not work.

It does work, but may breaks web forms as you've shown, *if* the site
doesn't use fully qualified URLs. Yet all that hardly matters if the
response just says "Thanks for your transaction".

Of course streaming the full response back is hardly ever going to happen.
It's more likely that you just search for a certain text block in the
original response and insert that text block ("Thanks for your
transaction...") on your own page. At the end of the day, this is a poor
man's application integration sceneario using HTML instead of SOAP or some
other web friendly remoting protocol.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top