开发者

help in c# and webclient class

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 开发者_StackOverflow社区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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜