C# Cefsharp 获取cookie 和设置cookie

设置cookie 

var cook = Cef.GetGlobalCookieManager();
cook.SetCookieAsync(url, new CefSharp.Cookie
{
                    Domain = "",
                    Name = "",
                    Value = "",
});

读取cookie 

  private  void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
            CookieVisitor visitor = new CookieVisitor();
            visitor.SendCookie += visitor_SendCookie;
            ICookieManager cookieManager = browser.GetCookieManager();
            cookieManager.VisitAllCookies(visitor);
}
private void visitor_SendCookie(CefSharp.Cookie obj)
{
            //obj.Domain.TrimStart('.') + "^" +
            string cookies = obj.Name + ":" + obj.Value + ";";
}
public class CookieVisitor : CefSharp.ICookieVisitor
    {
        public event Action SendCookie;
        public void Dispose()
        {
            
        }

        public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
        {
            deleteCookie = false;
            if (SendCookie != null)
            {
                SendCookie(cookie);
            }

            return true; 

        }

       

    }

 

你可能感兴趣的:(cookie,cefsharp)