开发者

Android WebView - reset HTTP session

开发者 https://www.devze.com 2023-01-28 09:38 出处:网络
I\'m using a WebView in a开发者_StackOverflow中文版n Android app. I periodically to be able to reset the WebView http session so that the server app it is accessing will initialise a new session. I ca

I'm using a WebView in a开发者_StackOverflow中文版n Android app. I periodically to be able to reset the WebView http session so that the server app it is accessing will initialise a new session. I can't find how to do this - is this possible ?

Rgds, Kevin.


I think the clear cookie can make session close. More about session

CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();


import android.webkit.CookieManager;

CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();

removeSessionCookie() allows to keep other cookies but clear sessions.


There are a couple of things you can do to clear the webview depending exactly what you want to do:

webView.clearCache(true);

webView.clearHistory();

webView.destroy();


This worked for me:

WebStorage.getInstance().deleteAllData()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号