CEF设置cookie


void CBrowserFrame::SetCookie()
{
    CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
    CefCookie cookie;
    CefString(&cookie.name).FromASCII("Venus_UserInfo");
    CefString(&cookie.value).FromASCII(g_meta.cookie);
    CefString(&cookie.domain).FromASCII("venus.sogou-inc.com");
    CefString(&cookie.path).FromASCII("/");
    cookie.has_expires = true;
    cookie.expires.year = 2200;
    cookie.expires.month = 4;
    cookie.expires.day_of_week = 5;
    cookie.expires.day_of_month = 11;
    CefPostTask(TID_IO, NewCefRunnableMethod(manager.get(), &CefCookieManager::SetCookie, CefString("http://venus.sogou-inc.com"), cookie));
}

 

就是这段代码, 关键在于最后一句, 这里是开启了一个新的IO thread, 设置cookie一定要在io线程里面做.为什么呢? 我目前不能答复你, 随着我们对CEF内核的深入, 相信会水落石出.

使用情景, 比如, 想要直接登入一个网站, 可以通过设置cookie实现.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM