简体   繁体   English

c#和webclient类的帮助

[英]help in c# and webclient class

I need to enable cookie with webclient ( windowsForm Project ) 我需要使用webclient启用cookie(WindowsForm Project

I found a solution for it in this link 我在此链接中找到了解决方案

Using CookieContainer with WebClient class 将CookieContainer与WebClient类一起使用

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. 我需要有人向我解释如何正确应用它,如果您有其他解决方案请向我提供。

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 . 也可以在这里查看我以前对类似主题的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM