I am trying to obtain the values of cookies from a particular website. The problem is, when I run the following code, it only loops through 4 of 10 cookie values present. Furthermore, the values are turning up as deleted: Reference
Then I came across this code, which states it will loop through every cookie value and obtain its values: Reference
The problem with the above, I can't seem to find a reference to "Request". I am using the libraries "using System.Net and
using System.Web", so I am unsure why Request is not being recognized.
My goal is to retrieve one cookie value so that when a user from my website logs in, my C# application will recognize that user.
Thanks for any help!
Code:
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://www.mysite.com");
Request.CookieContainer = new CookieContainer();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
foreach (Cookie cook in Response.Cookies)
{
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
}
Code:
int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;
MyCookieColl = Request.Cookies;
String[] arr1 = MyCookieColl.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
MyCookie = MyCookieColl[arr1[loop1]];
String[] arr2 = MyCookie.Values.AllKeys;
}
using System.Web", so I am unsure why Request is not being recognized.
My goal is to retrieve one cookie value so that when a user from my website logs in, my C# application will recognize that user.
Thanks for any help!
Comment