我正在将 CEF 与我的 MFC 应用程序集成(我正在关注 this tutorial )并且我不知道如何获取请求 cookie,我正在尝试使用 OnBeforeBrowse 方法但是仍然没有成功我也尝试了 OnResourceResponse 但我只设法在响应中获取一些 cookie。
一些初学者问题:GetFirstPartyForCookies 方法的作用是什么?我阅读了文档,但仍然不明白。 我应该使用 CefCookieManager 吗?我想我应该使用 VisitAllCookies 方法,但访问者参数不能为空它给了我一个断言,我正在尝试:
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(NULL);
CefRefPtr<CefCookieVisitor> visitor;
manager->VisitAllCookies(visitor);
任何帮助或提示将不胜感激。
最佳答案
在 CEF forum 上找到了这个答案.
要检索 cookie,我必须创建自己的派生自 CefCookieVisitor 的类,然后调用 VisitAllCookies
CefRequestHandler::ReturnValue ClientHandler::OnBeforeResourceLoad(CefRefPtr< CefBrowser > browser,
CefRefPtr< CefFrame > frame,
CefRefPtr< CefRequest > request,
CefRefPtr< CefRequestCallback > callback)
{
auto strURL = request->GetURL();
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(NULL);
CefRefPtr<MyCookieVisitor> visitor = new MyCookieVisitor();
manager->VisitAllCookies(visitor);
return RV_CONTINUE;
}
关于c++ - 如何在CEF + MFC中获取cookies?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42860119/