CEF 设置Cookie

参考文档:http://magpcss.org/ceforum/apidocs3/projects/(default)/CefCookieManager.htmlcss

转载:http://www.javashuo.com/article/p-vetxscmu-kb.htmlhtml

转载:https://blog.csdn.net/wangshubo1989/article/details/50520370c++

转载:https://blog.csdn.net/lee353086/article/details/42970909api

转载:http://www.itboth.com/d/qyAB7j/cookie-cef-c++浏览器

Cookie是什么:

简单地说,cookie 就是浏览器储存在用户电脑上的一小段文本文件。cookie 是纯文本格式,不包含任何可执行的代码。一个 Web 页面或服务器告知浏览器按照必定规范来储存这些信息,并在随后的请求中将这些信息发送至服务器,Web 服务器就能够使用这些信息来识别不一样的用户。大多数须要登陆服务器

的网站在用户验证成功以后都会设置一个 cookie,只要这个 cookie 存在并能够,用户就能够自由浏览这个网站的任意页面。再次说明,cookie 只包含数据,就其自己而言并不有害。cookie

设置Cookie的失效时间:session

若是Cookie没有设置expires属性,那么 cookie 的生命周期只是在当前的会话中,dom

关闭浏览器意味着此次会话的结束,此时 cookie 随之失效。ide

CEF3中,CefCookieManager这个类就是用来管理cookies的。

在头文件cef_cookies中,在cef_cookies_capi.h里,有详细的注释,和上边连接里的文档说明同样。

Cookies的管理无外乎Cookies的设置、获取、删除、查找,外加一个存储位置的设置。

Method Summary
 static CefRefPtr< CefCookieManager > CreateManager( const CefString& path, bool persist_session_cookies, CefRefPtrCefCompletionCallback > callback ) 
          Creates a new cookie manager.
 virtual bool DeleteCookies( const CefString& url, const CefString& cookie_name, CefRefPtrCefDeleteCookiesCallback > callback )= 0 
          Delete all cookies that match the specified parameters.
 virtual bool FlushStoreCefRefPtrCefCompletionCallback > callback )= 0 
          Flush the backing store (if any) to disk.
 static CefRefPtr< CefCookieManager > GetGlobalManagerCefRefPtrCefCompletionCallback > callback ) 
          Returns the global cookie manager.
 virtual bool SetCookie( const CefString& url, const CefCookie& cookie, CefRefPtrCefSetCookieCallback > callback )= 0 
          Sets a cookie given a valid URL and explicit user-provided cookie attributes.
 virtual bool SetStoragePath( const CefString& path, bool persist_session_cookies, CefRefPtrCefCompletionCallback > callback )= 0 
          Sets the directory path that will be used for storing cookie data.
 virtual void SetSupportedSchemes( const std::vector< CefString >& schemes, CefRefPtrCefCompletionCallback > callback )= 0 
          Set the schemes supported by this manager.
 virtual bool VisitAllCookiesCefRefPtrCefCookieVisitor > visitor )= 0 
          Visit all cookies on the IO thread.
 virtual bool VisitUrlCookies( const CefString& url, bool includeHttpOnly, CefRefPtrCefCookieVisitor > visitor )= 0 
          Visit a subset of cookies on the IO thread.
std::wstring username_key = L"username"; std::wstring username_value = L"chechen"; std::wstring domain = L"www.cnblogs.com/chechen" CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(); CefCookie cookie; CefString(&cookie.name).FromWString(username_key.c_str()); CefString(&cookie.value).FromWString(username_value.c_str()); CefString(&cookie.domain).FromWString(domain.c_str()); CefString(&cookie.path).FromASCII("/"); cookie.has_expires = true;//设置Cookie时间
    cookie.expires.year = 2200; cookie.expires.month = 4; cookie.expires.day_of_week = 5; cookie.expires.day_of_month = 11; domain = L"https://" + domain; CefPostTask(TID_IO, NewCefRunnableMethod(manager.get(), &CefCookieManager::SetCookie,CefString(domain.c_str()), cookie));

注意:cookie.domain是不带”https://”的,而CefString(domain.c_str())中的domain是带”https://“的,必定要注意。

相关文章
相关标签/搜索