How to make multiple or consecutive webrequests using the same connection or session

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm attempting to make WebRequest or HttpWebRequest requests to a
router's HTTP configuration interface. I cannot navigate directly to
the page I need because the router will automatically redirect
(somehow...I'm not sure if it's an http redirect or what) the request
to the router's initial page. So, after the first request, I need to
make a second request to navigate to the page I want. However, the
connection/session to the router seems to be lost and it again
redirects me to the router's initial page.

I have tried setting AllowAutoRedirect to False, but that didn't help.

Code Sample:

-----
Dim WR As HttpWebRequest
Dim SR As System.io.StreamReader

'This makes the first request
WR = CType(WebRequest.Create(sDestinationURI), HttpWebRequest)
WR.Credentials = New Net.NetworkCredential(Me.txtRouterUserID.Text,
Me.txtRouterPW.Text)

SR = New System.IO.StreamReader(WR.GetResponse.GetResponseStream)
Me.txtRouterHTMLSource.Text = WR.GetResponse.Headers.ToString()
Me.txtRouterHTMLSource.Text += SR.ReadToEnd
SR.Close()

'This makes the 2nd request, but I still get returned to the
'initial page.
WR = CType(WebRequest.Create(sDestinationURI), HttpWebRequest)
WR.Credentials = New Net.NetworkCredential(Me.txtRouterUserID.Text,
Me.txtRouterPW.Text)

SR = New System.IO.StreamReader(WR.GetResponse.GetResponseStream)
Me.txtRouterHTMLSource.Text = WR.GetResponse.Headers.ToString()
Me.txtRouterHTMLSource.Text += SR.ReadToEnd
SR.Close()

-----

Thanks for any and all help.

-Ed

.



Relevant Pages

  • Re: Internet/Web classes in .NET/VC++...
    ... open a child window and request the result of the query from another page ... If I use the C++ WebClient class, I can successfully get the end results. ... queries, I cannot use the name-value form for sending data. ... So, I tried the HTTPWebRequest class (inherited from WebRequest, specific ...
    (microsoft.public.dotnet.languages.vc)
  • Re: forms auth, authenticate against already encrypted password?
    ... i actually tried using a WebClient implementation first, sending a POST request to login.aspx which handled Request.Formetc in the Page_Load event. ... i have tried it again using the HttpWebRequest class and now i can share the CookieContainers, ... programamtically send request to forms authentication protected webpage. ... you can consider share a cookie container ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: WebResponse.GetResponseStream() exception
    ... programmatically request some web pages, ... Does this problem frequently occur when you use HttpWebRequest class to ... here is a test program which can programmatically request the ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework)
  • Re: Is it possible to turn off "HTTP Keep-Alive" globally in app.config?
    ... If the server hosting the Web Service is under your control can't you just ... getting the ConstructorInfo for HttpWebRequest, ... instance make new TCP connection for each web service request. ... SoapHttpClientProtocol has a protected method GetWebRequest(System.Uri ...
    (microsoft.public.dotnet.languages.csharp)
  • True asynchronous HttpWebRequest implementation with abort and timeout
    ... I'm tired of seeing all these asynchronous HttpWebRequest ... How do I implement an cancel method that aborts the request? ... private static void RespCallback(IAsyncResult asynchronousResult) ... // Read the response into a Stream object. ...
    (microsoft.public.dotnet.framework)