Android: HttpClient与Webview共享cookies
本人最近和别人合做一个app应用,app加webview。
app登陆有webview也要是登陆状态,解决的办法是app登陆后把设置下cookie
httpclient与webview需要进行cookie共享,因为如果不共享,那么假设你在httpclient进行了登录,然后用webview里打开那些login之后才能看的page,就会叫你再login
DefaultHttpClient httpclient=....; String toUrl="https://cap.cityu.edu.hk/studentlan/details.aspx....."; List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (! cookies.isEmpty()){ CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); //sync all the cookies in the httpclient with the webview by generating cookie string for (Cookie cookie : cookies){ String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain(); cookieManager.setCookie(toUrl, cookieString); CookieSyncManager.getInstance().sync(); } }
相关推荐
houmenghu 2020-11-17
kentrl 2020-11-10
逍遥友 2020-10-26
jincheng 2020-09-01
Blueberry 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
阳光之吻 2020-08-03
PkJY 2020-07-08
hzyuhz 2020-07-04
89407707 2020-06-27
服务器端攻城师 2020-06-26
阳光岛主 2020-06-25
笨重的蜗牛 2020-06-20
xuanwenchao 2020-06-14
Lophole 2020-06-13
明瞳 2020-06-12
songerxing 2020-06-11