How do I transfer user to another server after POST

P

Piotr Strycharz

Hi all

I do have a problem.

How can I transfer user to another server using POST. The problem is that
Server.Transfer (preserves form data) works just in current server.
Response.Redirect - uses GET method. However I have to open remote server
page using POST method. Normally this can be achieved using <form
ACTION="remote-page-url"> tag. However this is impossible with ASP.NET.
Also, using WebRequest class is not good solution, as I can post to and read
data from remote server, but user browser itselft is still connected to my
server.

Regards.
 
P

Patrice

TYhis is not an ASP.NET limitation (an "ASP.NET" page is anyway just an
HTML Page). At worst you could do something like a pure HTML Page that
contains the data as hidden field and that posts to the target page when
loaded...

That said I'm not sure it works (depending perhaps on user settings) as IMO
posting accross domains may sometimes be blocked ?

What thinks the owner of the page. Perhaps could a provide a GET version ?

Patrice
 
P

Piotr Strycharz

U¿ytkownik "Patrice said:
TYhis is not an ASP.NET limitation (an "ASP.NET" page is anyway just an
HTML Page).

Well - actually it is. I cannot provide my ACTION element in FORM
What thinks the owner of the page. Perhaps could a provide a GET version ?

Not possible. It is credit card verifier that allows parameters only as POST
data due to security reasons.

Piotr
 
P

Patrice

Sorry, I meant actually this is not an *HTML* limitation. Let's proceed with
take 2 hopefully more clearly.

You could then change the action attribute client side using JavaScript.

My first suggestion expressed more clearly was to create an HTML page by
yourself (using response.write). You could keep your current ASP.NET page
and on postback response.write those fields as hidden value on a page that
is immediatly submitted (using JavaScript)...

As a side note, I don't really understand why the user should be really
directed to the verification site. Shouldn't the verification process be
transparent to the user and see he is still on your site ?

Patrice
 
R

Rick Spiewak

You can create the post yourself
Here's some code I use to post a credit card transaction, which returns to
the caller. You can then redirect to an acknowledgement page:

Private Function viaKlixPostTransaction(ByVal trans As
viaKlixTransaction) As String
modErr.EnterFunction("OrderForm.aspx.vb.viaKlixPostTransaction")
Dim sbldr As New StringBuilder
Dim params As NameValueCollection = trans.GetValues
Dim iEnum As IEnumerator = params.Keys.GetEnumerator

' Build the request string from the parameters
Do While iEnum.MoveNext
Dim sKey As String = iEnum.Current
If Not params.Item(sKey) Is Nothing AndAlso
params.Item(sKey).ToString <> "" Then
sbldr.Append(sKey)
sbldr.Append("=")
sbldr.Append(Server.UrlEncode(params.Item(sKey)))
sbldr.Append("&")
End If
Loop
sbldr.Remove(sbldr.Length - 1, 1) 'Remove trailing "&"

'Post the request
Dim dataResponse As String
Dim dataBody As String = sbldr.ToString
Dim webResponse As HttpWebResponse
Dim webRequestStream As System.IO.Stream
Dim webRequest As HttpWebRequest
Dim responseStream As Stream

' Create the RequestStream
Try
webRequest =
webRequest.Create("https://www2.viaklix.com/process.asp")

' Note - "KeepAlive = False" seems to be needed to avoid errors,
apparently caused by the client
' (this application) thinking the connection is being
maintained while the server or
' firewall may disconnect it. Apparently, if the client
doesn't maintain it, it will know
' enough to re-establish it when it needs it.
webRequest.KeepAlive = False

webRequest.Method = "POST"
webRequest.ContentType = "application/x-www-form-urlencoded"

' Create request body
webRequest.ContentLength = dataBody.Length
webRequestStream = webRequest.GetRequestStream()
Catch ex As Exception
modErr.WriteLog("Creating RequestStream: " & ex.ToString, 0)
End Try

' Write the WebRequest
Try
Dim writer As New StreamWriter(webRequestStream)
writer.Write(dataBody)
'TODO - writer.close can probably go into a Finally block...
Try 'Getting an exception on this shouldn't stop us...
writer.Close() 'Closes the StreamWriter and the underlying
stream
Catch ex As Exception
modErr.WriteLog("Writer.Close: " & ex.ToString, 0)
End Try

Catch ex As Exception ' Catches error on writer.write
modErr.WriteLog(ex.ToString, 0)
modErr.WriteLog(dataBody, 1) 'Looking for data dependency
modErr.ExitFunction()
Return Nothing

End Try

' Get the response from viaKlix
Try
webResponse = webRequest.GetResponse()
responseStream = webResponse.GetResponseStream()

Dim readStream As New System.IO.StreamReader(responseStream)
dataResponse = readStream.ReadToEnd

readStream.Close() 'Closes the StreamReader and the underlying
stream

modErr.ExitFunction()
Return dataResponse

Catch ex As Exception
modErr.WriteLog("Reading Response: " & ex.ToString, 0)
modErr.ExitFunction()
Return Nothing
End Try

End Function
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top