Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I made a application for getting all cookies on a website but I noticed the app only outputs a few. Why is this happening and is this fixable?

What I have tried:

C#
try
{

string url = textBox1.Text;
               
HttpWebRequest myCall = (HttpWebRequest)WebRequest.Create(url); 

myCall.CookieContainer = new CookieContainer();

response = (HttpWebResponse)myCall.GetResponse();

myCall.AllowAutoRedirect = true;

foreach (Cookie cookie in response.Cookies)
{                   
    listBox1.Items.Add(cookie.Name);
     listBox1.Items.Add(cookie.Value);
}

myCall.Abort();

}
catch(Exception ex)
{
 MessageBox.Show(ex.Message);
}
Posted
Updated 18-Oct-17 0:11am
v2
Comments
ZurdoDev 17-Oct-17 14:29pm    
That looks right. Which ones are missing?
Steve44 17-Oct-17 15:51pm    
Can you please describe with what you are comparing the list of cookies you get in your program above? Are you comparing with the cookies a browser might receive from the same website? Or do you know, which cookies the website is supposed to send?
Without this information it is difficult to identify any reason for the missing cookies.

You can't.
For security reasons you can not get all cookies only those related to your session/domain...
 
Share this answer
 
Cookies are stored on the client, not the server so you can't get all cookies from a request to the web server. Your code is examining the response so you'll only see the cookies that are being *set* on that response, and a web site doesn't set all cookies every time. For example when you add to basket if you have no basket id in your cookie the site will add a basket id cookie and you'll see that cookie in the result of the add to basket page. However from then on you won't see that cookie being set as it is only set when the basket is created. From then on it is the client who has to manage that cookie.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900