zoukankan      html  css  js  c++  java
  • Android 应用内HttpClient 与 WebView 共享 Cookie

    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();
    	}
    }
    

    httpclient 与 webview需要进行cookie 共享,因为如果不共享,那么假设你在httpclient进行了登录,然后用webview里打开那些login之后才能看的page,就会叫你再login;

    一般我会把 httpclient 设置为静态的;

    转载请注明出处:http://duwei.cnblogs.com/
  • 相关阅读:
    Unity调试模式设置辅助线是否可见
    Gizmos绘制塔防游戏网格
    JS offsetparent 问题
    JS 图像延迟加载
    JS image对象
    JS 瀑布流
    JS 对象
    JS node
    Vue+element 实现表格的增加行、根据索引删除行的功能
    Java的集合框架
  • 原文地址:https://www.cnblogs.com/duwei/p/3896835.html
Copyright © 2011-2022 走看看