当前位置:网站首页>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.
边栏推荐
- Introduction to deep learning (II) -- univariate linear regression
- study hard and make progress every day
- Retirement plan fails, 64 year old programmer starts work again
- Realize file download through the tag of < a > and customize the file name
- (完美解决)matplotlib图例(legend)如何自由设置其位置
- Go language interface learning notes
- 1115 counting nodes in a BST (30 points)
- Promise
- Detailed explanation of yolov5 training own data set
- Audio Focus Series: write a demo to understand audio focus and audiomananger
猜你喜欢

ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
![[research materials] 2021 China's game industry brand report - Download attached](/img/b7/a377b0b7c742078e2feb28ebfbca62.jpg)
[research materials] 2021 China's game industry brand report - Download attached
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree

Cross platform plug-in flutter for displaying local notifications_ local_ notifications

Detailed explanation of yolov5 training own data set

SSM framework integration

JQ style, element operation, effect, filtering method and transformation, event object

Compile and decompile GCC common instructions

Three representations of signed numbers: original code, inverse code and complement code

Differences among bio, NiO and AIO
随机推荐
The IntelliJ platform completely disables the log4j component
Redis 入门和数据类型讲解
Redis Introduction et explication des types de données
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Introduction to deep learning - definition Introduction (I)
【实战项目】自主web服务器
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
在PyCharm中配置使用Anaconda环境
Interface frequency limit access
XML配置文件
Basic knowledge of reflection (detailed explanation)
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Notes | numpy-07 Slice and index
酒店公共广播背景音乐-基于互联网+的酒店IP网络广播系统设计
My first Smartphone
MySQL master-slave configuration
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Kept hot standby and haproxy
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément