參考文檔: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, CefRefPtr< CefCompletionCallback > callback ) Creates a new cookie manager. |
virtual bool |
DeleteCookies( const CefString& url, const CefString& cookie_name, CefRefPtr< CefDeleteCookiesCallback > callback )= 0 Delete all cookies that match the specified parameters. |
virtual bool |
FlushStore( CefRefPtr< CefCompletionCallback > callback )= 0 Flush the backing store (if any) to disk. |
static CefRefPtr< CefCookieManager > |
GetGlobalManager( CefRefPtr< CefCompletionCallback > callback ) Returns the global cookie manager. |
virtual bool |
SetCookie( const CefString& url, const CefCookie& cookie, CefRefPtr< CefSetCookieCallback > 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, CefRefPtr< CefCompletionCallback > callback )= 0 Sets the directory path that will be used for storing cookie data. |
virtual void |
SetSupportedSchemes( const std::vector< CefString >& schemes, CefRefPtr< CefCompletionCallback > callback )= 0 Set the schemes supported by this manager. |
virtual bool |
VisitAllCookies( CefRefPtr< CefCookieVisitor > visitor )= 0 Visit all cookies on the IO thread. |
virtual bool |
VisitUrlCookies( const CefString& url, bool includeHttpOnly, CefRefPtr< CefCookieVisitor > 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://「的,必定要注意。