ZuZuPetals
asked on
C# HttpWebRequest: Cookie is downloaded but collections are empty!
The following does a simple GET from a classic ASP page:
Here is a dump of the WebHeaderCollection:
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.somesite.asp");
request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
request.CookieContainer = cookieContainer;
request.KeepAlive = true;
request.Accept = null;
request.UseDefaultCredentials = true;
request.Proxy = null;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("StatusCode=" + response.StatusCode);
Console.WriteLine("cookieContainer.Count=" + cookieContainer.Count);
Console.WriteLine("response.Cookies.Count=" + response.Cookies.Count)
But both collections are empty. Any ideas why?Here is a dump of the WebHeaderCollection:
Content-Length: 128045The cookie is clearly there!
Content-Type: text/html
Date: Thu, 13 Sep 2012 23:46:59 GMT
Expires: Wed, 12 Sep 2012 23:46:58 GMT
Set-Cookie: ,ASPSESSIONIDAATAAQAB=JGEEHPOAKHCNLF IJLDFIIKDL ; path=/
Server: Microsoft-IIS/6.0
Cache-control: private
Have you tried inspecting the cookies of the response?
ASKER
Yes, please see line 16.
Ah, I completely glossed over that bit. I'll see if I can test it out later this evening.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No answer was given by community, but I offered a workaround.