当前位置:网站首页>Research on cookies in WebView
Research on cookies in WebView
2022-07-28 23:06:00 【ZZ White Dragon】
1.webview cookie Keep it locally
Project use WebView In fact, it will automatically Cookie Save in local database . The path to save is data/data/package_name/app_WebView/Cookies Though not .db At the end of the , It's actually a .db file , If the validity period is not set , Unless websid,sid Replace , It won't fail
2.webview Medium cookie It will not be cleared as the page closes
conversation cookie stay WebView It will not expire when closed , You have to manage it yourself .
Turn on cookie
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
1. Set up cookie:
In the parameter URL In the process of use, it is basically the domain name . for example https://www.baidu.com/ You can make www.baidu.com
Cookie The acquisition of the list varies according to the storage method of your own items . For example, using SharedPreferences and HashMap
Pay attention to for loop Conduct setCookie(String url, String value) call . There are blogs on the Internet that use semicolons to splice manually value Values can cause Cookie Cannot be set completely or invalid
Be careful value The value of is to use key=value The complete form of . Document tips the cookie as a string, using the format of the ‘Set-Cookie’ HTTP response header
CookieSyncManager Is an obsolete class ,Api21 in WebView Can automatically synchronize .
CookieSyncManager.getInstance().sync(); An alternative to this method is cookieManager.flush();
Cookie The synchronization method should be in WebView Of setting After set up, call , Otherwise it will not work .
call loadUrl(url); The previous sentence calls this method to Cookie Synchronous operation .
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie(murl, “username=” + nickName + “;”);//cookies Is in HttpClient From cookie
cookieManager.setCookie(murl, “websid=” + currentUser.getSid() + “;”);//cookies Is in HttpClient From cookie
cookieManager.setCookie(murl, “sid=” + currentUser.getSid() + “;”);//cookies Is in HttpClient From cookie
cookieManager.setCookie(murl, “userid=” + currentUser.getId() + “;”);//cookies Is in HttpClient From cookie
cookieManager.setCookie(murl, “t3kwid=” + currentUser.getId() + “;”);//cookies Is in HttpClient From cookie
cookieManager.setCookie(murl, “uph=” + “;”);//cookies Is in HttpClient From cookie
CookieSyncManager.getInstance().sync();
2. Sync cookie:
public void onPageFinished(WebView view, String url) {
CookieManager cookieManager = CookieManager.getInstance();
String cookieStr = cookieManager.getCookie(url);
String[] split = cookieStr.split(";");
}
3. eliminate cookie
CookieManager cookieManagerStore = CookieManager.getInstance();
cookieManagerStore.removeAllCookie();
边栏推荐
- Invest 145billion euros! EU 17 countries announce joint development of semiconductor technology
- Will Qualcomm and MediaTek chips soon be sold, and will they surpass Huawei to become the first in China?
- Reading of "robust and communication efficient federated learning from non-i.i.d. data"
- 软件测试工具fiddler postman jmeter charlse核心功能总结
- pg_ Installation and use of RMAN "PostgreSQL"
- One of the experience of solving problems with code error reporting: CUDA does not match pytorch
- A new MPLS note from quigo, which must be read when taking the IE exam ---- quigo of Shangwen network
- A new paradigm of distributed deep learning programming: Global tensor
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- 芯华章宣布完成超2亿A轮融资,全面布局EDA2.0研发
猜你喜欢
frontiers出版社投稿记录(附状态变化)
Target detection notes - overview and common data sets
Yolov5 improvement 12: replace backbone network C3 with lightweight network shufflenetv2
cnpm安装步骤
18 diagrams, intuitive understanding of neural networks, manifolds and topologies
安全狗入选《云安全全景图2.0》多个细项
Torch.fft.fft 2. () error reporting problem solution
Improvement 17 of yolov5: cnn+transformer -- integrating bottleneck transformers
There are four ways for Nacos to configure hot updates and multiple ways to read project configuration files, @value, @refreshscope, @nacosconfigurationproperties
【C语言】三子棋小游戏实现
随机推荐
Improvement 11 of yolov5: replace backbone network C3 with lightweight network mobilenetv3
xshell7,xftp7个人免费版官方下载,无需破解,免激活,下载即可使用
无代码开发平台通讯录入门教程
《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》
A new paradigm of distributed deep learning programming: Global tensor
Xshell7, xftp7 personal free version official download, no need to crack, no activation, download and use
The simple neural network model based on full connection layer MLP is changed to the model based on CNN convolutional neural network
shell脚本基础——Shell运行原理+变量、数组定义
Empowering Chinese core entrepreneurs! See how Moore elite solves the development problems of small and medium-sized chip Enterprises
赋能中国芯创业者!看摩尔精英如何破解中小芯片企业发展难题
[physical application] atmospheric absorption loss with matlab code
The US FCC provided us $1.6 billion to support domestic operators to remove Huawei and ZTE equipment
【C语言】三子棋小游戏实现
Written questions and answers of software test interview (software test question bank)
DirectX repair tool download (where is exagear simulator package)
投资1450亿欧元!欧盟17国宣布联合发展半导体技术
A simple neural network model based on MLP full connection layer
Multi activity disaster recovery construction after 713 failure of station B | takintalks share
Improvement 16 of yolov5: replace backbone network C3 with lightweight network pp-lcnet
[3D target detection] 3dssd (II)