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

转载:https://www.cnblogs.com/guolixiucai/p/6994559.html

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

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

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

Cookie是什么:

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

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

设置Cookie的失效时间:

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

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

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 = ;
cookie.expires.month = ;
cookie.expires.day_of_week = ;
cookie.expires.day_of_month = ; 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://“的,一定要注意。

最新文章

  1. JMeter学习-024-JMeter 命令行(非GUI)模式详解(二)-执行代理设置
  2. MongoDB aggregate 运用篇 个人总结
  3. iphone dev 入门实例4:CoreData入门
  4. 实战Django:官方实例Part6
  5. PostgreSQL的 fdw 跨库使用
  6. 已经上架的app(可供销售)在AppStore上搜不到的解决办法
  7. Django入门笔记
  8. [补档][NOIP2015] 斗地主
  9. C++ STL vector详解
  10. 个人作业2:QQ音乐APP案例分析
  11. logback 三
  12. Redis 总结
  13. 关于HTTP的长连接和短连接
  14. C++虚基类的初始化
  15. Mac Python建立简单的本地服务器
  16. 写TXT文件
  17. 修改mysql数据默认存储路径
  18. naca0012
  19. [ReactVR] Add Lighting Using Light Components in React VR
  20. VS2017十五项新功能体验

热门文章

  1. gitlab的fork及源项目的同步
  2. webpack应用案例之美团app
  3. linux 远程连接ssh提示IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY解决
  4. mysql批量插入
  5. Gym 102028C - Supreme Command - [思维题][2018-2019 ACM-ICPC Asia Jiaozuo Regional Contest Problem C]
  6. 新建Maven项目时dtd约束出错
  7. Spring之IOC注入
  8. mybatis中namespace配置方式
  9. node获取windows pc 机器的标示
  10. Cocos Creator两个类相互引用(调用)