Android: HttpClient与Webview共享cookies
2015-03-11 11:38
393 查看
httpclient与webview需要进行cookie 共享,因为如果不共享,那么假设你在httpclient进行了登录,然后用webview里打开那些login之后才能看的page,就会叫你再login
[java] view
plaincopy
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();
}
}
[java] view
plaincopy
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();
}
}
相关文章推荐
- Android: HttpClient与Webview共享cookies
- android中HttpClient获取Session然后使用 WebView共享session的解决办法
- android中HttpClient获取Session然后使用 WebView共享session的解决办法(转)
- android中HttpClient获取Session然后使用 WebView共享session的解决办法(转)
- android系统内置HttpClient库(WebView+ Http(s)URLConnection(ok-http)+ HttpClient(apache-http))
- Android WebView 与HttpClient 共用本地cookie问题
- Android WebView 与OkhttpClient登录状态保持一致,建立SESSION会话
- android webview & httpclient 处理 ssl (https)验证
- android httpclient与webview cookie同步
- android使用webview登录,获取session传递到httpclient小例子
- SSO(Singl Sign On) HTTPClient 和webView共享Cookie
- android httpclient 与 webView cookie同步问题
- android WebView 和 HttpClient cookie同步
- android WebView 与 HttpClient Cookie
- Android WebView 与HttpClient 共用本地cookie问题
- android WebView 与 HttpClient Cookie
- android WebView 与 HttpClient Cookie
- android使用webview登录,获取session传递到httpclient小例子
- android WebView 与 HttpClient Cookie
- android httpclient与webview cookie同步