0

I need to enable cookie with webclient (windowsForm Project)

I found a solution for it in this link

Using CookieContainer with WebClient class

but I can not understand how to apply it ? should I create a new class for it (it does not work) or I need to change variables to make it suitable to my project ?

I need someone explain me how exactly apply it, and if you have a another solution supply me with it.

Community
  • 1
  • 1
user504363
  • 541
  • 2
  • 11
  • 25
  • you have already found your solution.. as suggested there create a new class and Inherit it from WebClient... if its not working provide us with some code and more details to see your use case. and how you are implementing it. – Shekhar_Pro Feb 09 '11 at 22:56
  • Ok, but how can I check the cookies stored ? – user504363 Feb 09 '11 at 23:03

1 Answers1

0

This would do it:

public class CookieMonsterWebClient : WebClient
{
    public CookieContainer Cookies { get; set; }

    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
        request.CookieContainer = Cookies;
        return request;
    }
}

Also check out my previous answer to a similar topic here.

Community
  • 1
  • 1
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
  • I am so sorry, but I can not understand exactly the way to enable webclient to store and display cookies, please some notes can help me – user504363 Feb 09 '11 at 23:25
  • what exactly do you mean by store and display? What is your use case for this? Can you update your question to say what you want to achieve? The code you have so far would help as well. – BrokenGlass Feb 09 '11 at 23:33