POST and redirect

E

ETK

Hi,
I need to POST data to some aspx page and after that redirect to this page
( page isn't on my local server where my page is). Is it possible to do this
from aspx code on server side?
Thanks,
Dalibor
 
K

Ken Cox [Microsoft MVP]

Hi Dalibor,

You could use the Webclient class for this. You need to know the names of
the Posted controls. Then do you response.redirect:


Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
Response.Redirect("http://msdn.microsoft.com/")
End Sub

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
E

ETK

Hi Ken,
I get next error: "The underlying connection was closed: Unable to connect
to the remote server.". I think that it is because I have to use PROXY
(probably I should set proxy settings somewhere in code). I'll try to solve
this.
But it seems to me that when I do Response.Redirect on the some page I do
POST, that it is a new request for page and page wouldn't get data my page
have to post. I need to post data and redirect with posted data to this page
(show result in browser).

Thanks,
Dalibor

Ken Cox said:
Hi Dalibor,

You could use the Webclient class for this. You need to know the names of
the Posted controls. Then do you response.redirect:


Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
Response.Redirect("http://msdn.microsoft.com/")
End Sub

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

ETK said:
Hi,
I need to POST data to some aspx page and after that redirect to this
page ( page isn't on my local server where my page is). Is it possible to
do this from aspx code on server side?
Thanks,
Dalibor
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top