POST data to external site

Discussion in 'ASP .Net' started by Wayne P., Dec 16, 2004.

  1. Wayne P.

    Wayne P. Guest

    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.
     
    Wayne P., Dec 16, 2004
    #1
    1. Advertising

  2. 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." <> wrote in message
    news:...
    > 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("&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.AppSettings.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.AppSettings.Get("ReturnURL") &

    "'
    > &gt;")
    > Response.Write("&lt;input type='hidden' name='cancel_URL' value='" &
    > System.Configuration.ConfigurationSettings.AppSettings.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.
    >
    >
     
    William F. Robertson, Jr., Dec 16, 2004
    #2
    1. Advertising

  3. Wayne P.

    Joerg Jooss Guest

    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
     
    Joerg Jooss, Dec 19, 2004
    #3
  4. 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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
     
    William F. Robertson, Jr., Dec 20, 2004
    #4
  5. Wayne P.

    Joerg Jooss Guest

    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
     
    Joerg Jooss, Dec 21, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    577
    Guest
    Feb 2, 2004
  2. Guest
    Replies:
    0
    Views:
    524
    Guest
    Feb 9, 2004
  3. jasontoolittle

    Post Form Data to External URL

    jasontoolittle, Sep 28, 2010, in forum: Java
    Replies:
    0
    Views:
    860
    jasontoolittle
    Sep 28, 2010
  4. jasontoolittle

    Post Form Data to External URL

    jasontoolittle, Sep 28, 2010, in forum: .NET
    Replies:
    0
    Views:
    1,334
    jasontoolittle
    Sep 28, 2010
  5. c676228
    Replies:
    2
    Views:
    138
    c676228
    Apr 30, 2007
Loading...

Share This Page