POST and redirect

  • Thread starter Thread starter ETK
  • Start date Start date
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
 
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]
 
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
 
Back
Top