How do I transfer user to another server after POST

Discussion in 'ASP .Net' started by Piotr Strycharz, Apr 22, 2004.

  1. 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.
     
    Piotr Strycharz, Apr 22, 2004
    #1
    1. Advertising

  2. Piotr Strycharz

    Patrice Guest

    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

    "Piotr Strycharz" <> a écrit dans le
    message de news:c683r7$83e$...
    > 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.
    >
    >
     
    Patrice, Apr 22, 2004
    #2
    1. Advertising

  3. U¿ytkownik "Patrice" <> napisa³ w wiadomo¶ci
    news:%...
    > 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
     
    Piotr Strycharz, Apr 22, 2004
    #3
  4. Piotr Strycharz

    Patrice Guest

    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


    "Piotr Strycharz" <> a écrit dans le
    message de news:c68e9g$2k1$...
    >
    > U¿ytkownik "Patrice" <> napisa³ w wiadomo¶ci
    > news:%...
    > > 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
    >
     
    Patrice, Apr 22, 2004
    #4
  5. Piotr Strycharz

    Rick Spiewak Guest

    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

    "Piotr Strycharz" <> wrote in message
    news:c68e9g$2k1$...
    >
    > U¿ytkownik "Patrice" <> napisa³ w wiadomo¶ci
    > news:%...
    > > 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
    >
     
    Rick Spiewak, Apr 23, 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. qwerty
    Replies:
    3
    Views:
    9,325
    Scott Allen
    Sep 30, 2004
  2. David Veeneman

    Server.Transfer() and POST data

    David Veeneman, Nov 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,291
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Nov 8, 2006
  3. CCY
    Replies:
    2
    Views:
    425
  4. Jim
    Replies:
    1
    Views:
    986
    Aaron Bertrand - MVP
    Jan 28, 2004
  5. Badri Narayanan
    Replies:
    4
    Views:
    198
    Badri Narayanan
    Mar 31, 2005
Loading...

Share This Page