G
Guest
I'm trying to login to a website with HttpWebRequest. The login page returns
a cookie and a HTTP 302 to redirect to the main page. I only need the cookie
to request the page I really need.
What I did is that:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.AllowAutoRedirect = false;
req.CookieContainer = new CookieContainer();
HttpWebResponse resp= (HttpWebResponse)req.GetResponse();
Now I expected the cookie in resp.Cookies, but this is empty
(resp.Cookies.Count == 0).
I sniffed the network traffic so I know exactly what came back from the
server:
HTTP/1.1 302 Moved
Date: Thu, 11 Nov 2004 12:24:32 GMT
Server: Apache/1.3.31 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2
mod_bwlimited/1.4 PHP/4.3.8 FrontPage/5.0.2.2634a mod_ssl/2.8.19
OpenSSL/0.9.6b
Set-Cookie: SessionId=2622-113773869; path=/; expires=Mon Jan 10 12:24:32
2005 GMT
Location: /cgi-bin/epg/myroom.cgi
Transfer-Encoding: chunked
Content-Type: text/plain
0
The set-cookie header is there! So why is resp.Cookies empty?
When I try with req.AllowAutoRedirect=true the redirect takes me to the main
page BUT also without sending the cookie, so the main page redirects back to
the login page.
Cheers,
Michael
a cookie and a HTTP 302 to redirect to the main page. I only need the cookie
to request the page I really need.
What I did is that:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.AllowAutoRedirect = false;
req.CookieContainer = new CookieContainer();
HttpWebResponse resp= (HttpWebResponse)req.GetResponse();
Now I expected the cookie in resp.Cookies, but this is empty
(resp.Cookies.Count == 0).
I sniffed the network traffic so I know exactly what came back from the
server:
HTTP/1.1 302 Moved
Date: Thu, 11 Nov 2004 12:24:32 GMT
Server: Apache/1.3.31 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2
mod_bwlimited/1.4 PHP/4.3.8 FrontPage/5.0.2.2634a mod_ssl/2.8.19
OpenSSL/0.9.6b
Set-Cookie: SessionId=2622-113773869; path=/; expires=Mon Jan 10 12:24:32
2005 GMT
Location: /cgi-bin/epg/myroom.cgi
Transfer-Encoding: chunked
Content-Type: text/plain
0
The set-cookie header is there! So why is resp.Cookies empty?
When I try with req.AllowAutoRedirect=true the redirect takes me to the main
page BUT also without sending the cookie, so the main page redirects back to
the login page.
Cheers,
Michael