当前位置:网站首页>Learn libcef together -- set cookies for your browser
Learn libcef together -- set cookies for your browser
2022-07-03 05:12:00 【Jiangnan - crossing the river with a reed】
I haven't written about for a long time libcef The article of , Because my understanding is very shallow .
We know that the browser has the function of remembering passwords , After login , You can log in directly by entering the domain name again . Most of the time through cookie To achieve .
For someone who hasn't touched web People who , Maybe I don't understand cookie?
Cookie, Sometimes in the plural Cookies, Refers to some websites in order to identify users 、 Conduct session Tracking data stored on the user's local terminal ( Usually encrypted ).
for instance , We create One browser, And navigate to the http://blog.csdn.net/ Website , Then you can login and other operations .
But if we give browser Set it up in advance cookie, such as username userinfo etc. . Then visit http://blog.csdn.net/ When ,cef The browser will read cookie Information in , Then displayed http://blog.csdn.net/ The home page is in login status .
therefore , The next question is how to cef Set up cookie?
Is in createbrowser Before or after createbrowser After that ?
The answer is before .
Let's first assume cookie The format of :
username = xxx
Go straight to the code :
std::wstring username_key = L"username";
std::wstring username_value = L"jiangtao";
std::wstring domain = L"blog.csdn.net"
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 = false;
domain = L"https://" + domain;
CefPostTask(TID_IO, NewCefRunnableMethod(manager.get(), &CefCookieManager::SetCookie,CefString(domain.c_str()), cookie));
// Create a browser
CefBrowserHost::CreateBrowser(info, g_web_browser_client.get(),
domain.c_str(), browserSettings, NULL);
What needs to be noted here is ,cookie.domain Is not to bring "https://" Of , and CefString(domain.c_str()) Medium domain It's with "https://“ Of , Be sure to pay attention to .
Let's see below. setcookie English document of :
SetCookie
public 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. This function expects each attribute to be well-formed. It will check for disallowed characters (e.g. the ‘;’ character is disallowed within the cookie value attribute) and fail without setting the cookie if such characters are found. If |callback| is non-NULL it will be executed asnychronously on the IO thread after the cookie has been set. Returns false if an invalid URL is specified or if cookies cannot be accessed.
Let's see below. setcookie English document of :
CreateManager
public static CefRefPtr< CefCookieManager > CreateManager( const CefString& path, bool persist_session_cookies, CefRefPtr< CefCompletionCallback > callback );
Creates a new cookie manager. If |path| is empty data will be stored in memory only. Otherwise, data will be stored at the specified |path|. To persist session cookies (cookies without an expiry date or validity interval) set |persist_session_cookies| to true. Session cookies are generally intended to be transient and most Web browsers do not persist them. If |callback| is non-NULL it will be executed asnychronously on the IO thread after the manager’s storage has been initialized.
边栏推荐
- [set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
- Web APIs exclusivity
- SSM framework integration
- 1103 integer factorization (30 points)
- es7创建索引容易犯的错误
- Pan details of deep learning
- 1094 the largest generation (25 points)
- Handler understands the record
- My first Smartphone
- Go practice - gorilla / handlers used by gorilla web Toolkit
猜你喜欢
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
leetcode406. Rebuild the queue based on height
Oracle SQL table data loss
leetcode435. Non overlapping interval
Yolov5 network structure + code + application details | CSDN creation punch in
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Shallow and first code
"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released
[practical project] autonomous web server
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
随机推荐
appium1.22. Appium inspector after X version needs to be installed separately
Sprintf formatter abnormal exit problem
Actual combat 8051 drives 8-bit nixie tube
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Kept hot standby and haproxy
[research materials] 2021 China's game industry brand report - Download attached
leetcode406. Rebuild the queue based on height
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
1107 social clusters (30 points)
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Common methods of JS array
Shuttle + Alluxio 加速内存Shuffle起飞
Retirement plan fails, 64 year old programmer starts work again
"Hands on deep learning" pytorch edition Chapter II exercise
Ueditor, FCKeditor, kindeditor editor vulnerability
Introduction to redis and explanation of data types
Detailed explanation of yolov5 training own data set
cookie session jwt
Messy change of mouse style in win system
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)