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
recoil@community.nospam - 26 Apr 2005 19:04 GMT
What you need to do is Persist the Credentails and the cookies. I
believe this is done by grabbing the cookies from the prior request and
then setting them on the new request.
emcinerney@yahoo.com - 27 Apr 2005 04:06 GMT
Thanks for the suggestion, but I still couldn't get it to work. I
created variables for CookieContainer and Credentials and set them from
the request's response. Then I used those variables to set those
properties on the new request object. The 2nd request works, but I
still get the initial page back. Oh, and when I checked the
CookieContainer object, the count was 0, so I don't think it's using
cookies. Any other suggestions?
> What you need to do is Persist the Credentails and the cookies. I
> believe this is done by grabbing the cookies from the prior request and
> then setting them on the new request.
Nathan S - 27 Apr 2005 15:08 GMT
Why do you feel the second request should get a different resonse to th
first one? (from your code, it looks like you're requesting the sam
uri twice)
If the second request's uri is different, then maybe you're gettin
redirected because you haven't authenticated properly?
N
--
Nathan
Feroze [msft] - 29 Apr 2005 23:57 GMT
What I would suggest is: try the same scenario with a browser, and sniff the
session with ethereal. Then, use the trace to figure out how the server is
persisting state to the client. Is it using
1) cookies
2) credentials
3) Connection persistence
4) some/all of the above?
If it is using cookies, make sure you set a CookieContainer on the
webrequest. For credentials, you will need to set a NetworkCredential.
For connection persistence, you can use the ConnectionGroupName property.
Set it to a unique name, and use the same name for all requests that you
want to share the connection.

Signature
feroze
-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.
See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
> I'm attempting to make WebRequest or HttpWebRequest requests to a
> router's HTTP configuration interface. I cannot navigate directly to
[quoted text clipped - 39 lines]
>
> -Ed