当前位置:网站首页>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();
边栏推荐
- Stm32f4 serial port burning [flymcu]
- 定了!哪吒S全系产品将于7月31日上市发售
- Improvement 16 of yolov5: replace backbone network C3 with lightweight network pp-lcnet
- Wheel 6: qserialport serial port data transceiver
- 【复制】互联网术语、简称、缩写
- 18张图,直观理解神经网络、流形和拓扑
- 【MongoDB】MongoDB数据库的基础使用,特殊情况以及Mongoose的安装和创建流程(含有Mongoose固定版本安装)
- Is 1E3 a floating point number?
- CGLIb 创建代理
- A new MPLS note from quigo, which must be read when taking the IE exam ---- quigo of Shangwen network
猜你喜欢

Reading of "robust and communication efficient federated learning from non-i.i.d. data"

《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》

Learning experience sharing 4: learning experience of yolov7

Improvement 11 of yolov5: replace backbone network C3 with lightweight network mobilenetv3

Thesis reading (1) - zfnet of classification

记录一下关于三角函数交换积分次序的一道题

定了!哪吒S全系产品将于7月31日上市发售

The safety dog has been selected into many details of cloud security panorama 2.0

MySQL常用的日期时间函数

《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》
随机推荐
NPM run dev, automatically open the browser after running the project
Console.log() console display... Solution
Es learning directory
leetcode101. 对称二叉树
Yolov5 improvement 12: replace backbone network C3 with lightweight network shufflenetv2
投资1450亿欧元!欧盟17国宣布联合发展半导体技术
Use FFT, matrix multiplication and conv2d to calculate convolution based on pytorch
It's settled! All products of Nezha s will be launched on July 31
赋能中国芯创业者!看摩尔精英如何破解中小芯片企业发展难题
Improvement 11 of yolov5: replace backbone network C3 with lightweight network mobilenetv3
Summary of C language learning content
无代码开发平台管理后台入门教程
(important) first knowledge of C language -- function
sql优化常用的几种方法
frontiers出版社投稿记录(附状态变化)
今年联发科5G芯片出货有望达到5000万套!
Symbol符号类型
1.8tft color screen test code (stm32f407ve)
Thesis reading (0) - alexnet of classification
Target detection notes -yolo