Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > POST data to external site

Reply
Thread Tools

POST data to external site

 
 
Wayne P.
Guest
Posts: n/a
 
      12-16-2004
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.


 
Reply With Quote
 
 
 
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      12-16-2004
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Joerg Jooss
Guest
Posts: n/a
 
      12-19-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      12-20-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> (E-Mail Removed)
>
>
>



 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      12-21-2004
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
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Post Form Data to External URL jasontoolittle ASP .Net 0 09-28-2010 04:43 PM
Post Form Data to External URL jasontoolittle Java 0 09-28-2010 04:38 PM
post xml data back to external resouces in B2B solution c676228 ASP General 2 04-30-2007 08:24 PM
Post data via the Post method in asp.net? (URGENT) Vishal ASP .Net 1 12-21-2004 06:14 AM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM



Advertisments