Creating POST data for Server.Transfer()?

  • Thread starter Thread starter David Veeneman
  • Start date Start date
D

David Veeneman

I want to programmatically create some POST data on a web server, then pass
that data to another web page that the server calls, using
Server.Transfer(). What's the best way to do that?

I'm programming some buttons that link to PayPal's shopping cart. The
shopping cart needs a bunch of data about the item being added, including
price. PayPal's sample markup puts the data in a hidden form, which the
button submits.

I'm concerned about the lack of security in that approach, so I want to have
the button invoke a method on the server that will assemble the POST data
that PayPal needs, and then redirect to PayPal. Right now I have a 'button
dispatch' page, which contains the data assembly and redirect
(Server.Transfer()) code in its Page_Load event.

What I can't figure out is how to get the POST data into the Request the
page will submit when it redirects to PayPal. What's the simplest way to do
this? Are there any examples? Thanks much.

David Veeneman
Foresight Systems
 
My bad. Server.Transfer won't call an external page or make a request.

I'm still stuck with my basic problem of needing to create POST data
programmatically and sending it to PayPall, and ending up on the PayPal page
I sent the data to. Any ideas?
 
David Veeneman said:
My bad. Server.Transfer won't call an external page or make a request.

I'm still stuck with my basic problem of needing to create POST data
programmatically and sending it to PayPall, and ending up on the PayPal
page I sent the data to. Any ideas?

It's not too hard - the POST data is just name-value pairs separated by
ampersands - just like on the query string. Oh, and you have to set the
content-type to the correct value as well.

I have an HttpPostRequest class that I threw together that neatly wraps up
form-style post requests. I'm not at the same location as that code right
now, but if no one else has posted some code by the end of the day, I'll see
if I can track down that class & make it available.

-cd
 
Carl said:
It's not too hard - the POST data is just name-value pairs separated
by ampersands - just like on the query string. Oh, and you have to
set the content-type to the correct value as well.

I have an HttpPostRequest class that I threw together that neatly
wraps up form-style post requests. I'm not at the same location as
that code right now, but if no one else has posted some code by the
end of the day, I'll see if I can track down that class & make it
available.

I was about to post the code and then I realized that I think you're asking
for something else. If I'm reading you right, you're writing code that's in
the code-behind (beside, inline, whatever) for an ASP.NET page and you need
to do a POST to PayPal and have the user's browser end up viewing the page
that PayPal returns. Is that right?

If that's what you're after, then the way to do it is to enlist the help of
the user's browser. Have your ASP.NET page return a page with a pre-filled
<form> (all elements can simply be <input type="hidden">) and use
client-side JScript to post that form in the client-side page load event.
That way, the user's browser actually makes the post & displayes the results
just like the user expects.

-cd
 
David said:
I want to programmatically create some POST data on a web server, then pass
that data to another web page that the server calls, using
Server.Transfer(). What's the best way to do that?

I'm programming some buttons that link to PayPal's shopping cart. The
shopping cart needs a bunch of data about the item being added, including
price. PayPal's sample markup puts the data in a hidden form, which the
button submits.

I'm concerned about the lack of security in that approach, so I want to have
the button invoke a method on the server that will assemble the POST data
that PayPal needs, and then redirect to PayPal. Right now I have a 'button
dispatch' page, which contains the data assembly and redirect
(Server.Transfer()) code in its Page_Load event.

What I can't figure out is how to get the POST data into the Request the
page will submit when it redirects to PayPal. What's the simplest way to do
this? Are there any examples? Thanks much.

David Veeneman
Foresight Systems

I have replied to this in a different newsgroup.

If you make a proper cross post instead of posting separate copies, you
will get a single thread instead of separate confused threads.
 

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

Back
Top