Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   POST data to external site (http://www.velocityreviews.com/forums/t92858-post-data-to-external-site.html)

Wayne P. 12-16-2004 08:06 AM

POST data to external site
 
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/steve...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.AppSett ings.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.AppSett ings.Get("ReturnURL") & "'
>")
Response.Write("<input type='hidden' name='cancel_URL' value='" &
System.Configuration.ConfigurationSettings.AppSett ings.Get("CancelURL") & "'
>")
Response.Write("</form>")
Response.Write("<script>")
Response.Write("document.StormPay.submit();")
Response.Write("</script>")

Thanks for the insight,

Wayne P.



William F. Robertson, Jr. 12-16-2004 05:16 PM

Re: POST data to external site
 
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

"Wayne P." <infinite@nospam-totalink.net> wrote in message
news:elEZ1Y04EHA.3908@TK2MSFTNGP12.phx.gbl...
> 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/steve...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("&lt;form name='StormPay'
> action='https://www.stormpay.com/stormpay/handle_gen.php' method='POST'
> &gt;")
> Response.Write("&lt;input type='hidden' name='test_mode' value='1' &gt;")
> 'Testing Flag
> Response.Write("&lt;input type='hidden' name='generic' value='1' &gt;")
> Response.Write("&lt;input type='hidden' name='payee_email' value='" &
>

System.Configuration.ConfigurationSettings.AppSett ings.Get("StormPayAccountE
> mail") & "' &gt;")
> Response.Write("&lt;input type='hidden' name='product_name' value='" &
> strProduct_name & "' &gt;")
> Response.Write("&lt;input type='hidden' name='return_URL' value='" &
> System.Configuration.ConfigurationSettings.AppSett ings.Get("ReturnURL") &

"'
> &gt;")
> Response.Write("&lt;input type='hidden' name='cancel_URL' value='" &
> System.Configuration.ConfigurationSettings.AppSett ings.Get("CancelURL") &

"'
> &gt;")
> Response.Write("&lt;/form&gt;")
> Response.Write("&lt;script&gt;")
> Response.Write("document.StormPay.submit();")
> Response.Write("&lt;/script&gt;")
>
> Thanks for the insight,
>
> Wayne P.
>
>




Joerg Jooss 12-19-2004 04:57 PM

Re: POST data to external site
 
William F. Robertson, Jr. wrote:
> 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,

--
Joerg Jooss
www.joergjooss.de
news@joergjooss.de




William F. Robertson, Jr. 12-20-2004 06:01 PM

Re: POST data to external site
 
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

"Joerg Jooss" <joerg.jooss@gmx.net> wrote in message
news:uLGF7ue5EHA.1120@TK2MSFTNGP11.phx.gbl...
> William F. Robertson, Jr. wrote:
> > 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,
>
> --
> Joerg Jooss
> www.joergjooss.de
> news@joergjooss.de
>
>
>




Joerg Jooss 12-21-2004 08:30 AM

Re: POST data to external site
 
William F. Robertson, Jr. wrote:
> 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,

--
Joerg Jooss
www.joergjooss.de
news@joergjooss.de




All times are GMT. The time now is 07:04 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.