.NET(C#) CefSharp 处理设置读取网站页面请求中的Cookie
时间:2022-11-19
1、设置cookie
var cookieManager = CefSharp.Cef.GetGlobalCookieManager(); await cookieManager.SetCookieAsync("http://" + domain, new CefSharp.Cookie() { Domain = domain, Name = name, Value = value, Expires = DateTime.MinValue });
2、读取cookie
1) 创建Cookie读取对象,继承接口 ICookieVisitor
public >CookieVisitor : CefSharp.ICookieVisitor
{
public event Action<CefSharp.Cookie> SendCookie;
public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
{
deleteCookie = false;
if (SendCookie != null)
{
SendCookie(cookie);
}
return true;
}
}
2) 在browser事件中进行处理
private void browser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e) { var cookieManager = CefSharp.Cef.GetGlobalCookieManager(); CookieVisitor visitor = new CookieVisitor(); visitor.SendCookie += visitor_SendCookie; cookieManager.VisitAllCookies(visitor); } /// 回调事件 private void visitor_SendCookie(CefSharp.Cookie obj) { cookies += obj.Domain.TrimStart('.') + "^" + obj.Name + "^" + obj.Value + "$"; }
相关文档:
https://github.com/cefsharp/CefSharp/wiki/Quick-Start
.Net(C#)cefsharpChrome 浏览器控件后台执行Iframe中的Js代码的方法
.NET(C#)cefsharp设置浏览器默认语言和userAgent及示例代码
.NET(C#) CefSharp CommandLine开关参数配置和读取网页源代码方法及示例代码
.NET(C#) CefSharp 下载获取页面中指定的文件图片视频等内容(.jpg、.js等)
特别声明:本站部分内容收集于互联网是出于更直观传递信息的目的。该内容版权归原作者所有,并不代表本站赞同其观点和对其真实性负责。如该内容涉及任何第三方合法权利,请及时与824310991@qq.com联系,我们会及时反馈并处理完毕。