Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POSTing to another form

Status
Not open for further replies.

SBGibson

Programmer
Apr 18, 2001
125
IT
Hi guys,

I've to connect my application to an online payment provider that requires I call his page passing parameters with a post action.
How can I do that during postback? I don't have all information in a form, some of them are takem from database and when I click "Pay" I would like to read them and do something like a Response.Redirect but with post action.
I think it's not possible to use WebClient cause I've to show the provider page that take care of the security of the payment.
Some suggestion? Thanks in advance.

Stevie B. Gibson
 
OK, this doesn't have a nice clean answer... but here are a couple of quick thoughts..

1. You could potentially build a "custom" form in your aspx file that does build the response from your db into hidden fields.. when the user submits the form it;s action doesn't postback or redirect, it goes to the webpage necessary..

2.I found that response.redirect doesn't always work the way you would like it to, but you can do a server.transfer and it will take "Form" values to the new page....(quite usefull for many applications)

3. Yes this can be done programaticly from inside your postback.. you will need to use the webresponse object to pull it off. I have done this, but I can't remember where I put the code.. I will post back if I can find it...


HTH

Rob

 
ha... I knew if I looked hard enough....

Read the comments-- This was a real mind bender for me, so I did make a few more than normal..

Post back if you have questions. I can probably look over it and figure it out again, but hopefully you have enough clues to get you going..

Rob

Code:
Dim myReq As HttpWebRequest = WebRequest.Create("[URL unfurl="true"]http://localhost/test.asp")[/URL]
        'Post or Get
        myReq.Method = "POST"
        ' The following type is needed for the post method, but clear for get..
        myReq.ContentType = "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
        ' this is the form data being submitted
        Dim postData As String = "Name=Rob&Password=PissOff"
        'this speicifys the lengthe of the form section
        myReq.ContentLength = postData.Length
        'Creates a stream from the Request that will be used to place the form data in..
        Dim newStream As Stream = myReq.GetRequestStream()
        'Build a steam writer to send our data to the "newStream" object
        Dim sw As New StreamWriter(newStream, Encoding.ASCII)
        'Write the "Form Data" to the stream for posting our request to the webserver
        sw.Write(postData)
        'close the the writer, we are ready
        sw.Close()

        'Set up the response object and bind it to the requestobject response..
        Dim res As HttpWebResponse = CType(myReq.GetResponse, HttpWebResponse)
        'bind the stream to the response object's responsestream
        newStream = res.GetResponseStream
        'Build a stream reader to retrieve the stream data from our response
        Dim sr As New System.IO.StreamReader(newStream)
        'read the stream into a string variable
        Dim s As String = sr.ReadToEnd()
        'Create a streamwriter for saving the output to a text file
        Dim tw As New System.IO.StreamWriter(txtDestination.Text)
        'Write the file
        tw.Write(s)
        'save the changes
        tw.Close()
        'get rid of the streamwriter
        tw = Nothing
        'return the string
        Return s
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top