WebView添加手动拼接Cookie

来源:互联网 发布:js 动态 array的方法 编辑:程序博客网 时间:2024/06/16 14:45
同样使用CookieManager
/**     * 同步一下cookie     */    public static void synCookies(Context context, String url) {        CookieSyncManager.createInstance(context);        CookieManager cookieManager = CookieManager.getInstance();        cookieManager.setAcceptCookie(true);        cookieManager.removeAllCookie();//移除        /**cookie*/        String expires = new Date(System.currentTimeMillis() + 86400000).toGMTString();        String host = Uri.parse(url).getHost().replace("www", "");        String uidCookie = "uid=\""+GlobalVariable.getCurrentUserID()+"\";$Domain=\"" + host + "\";$Path=\"" + NetConst.URL_COMPANY_FLOWERCHART_COOKIE_PATH +                "\";Max-Age=\"86400\";expires=\""+expires;//+"\";Secure;";        String cidCookie = "cid=\""+GlobalVariable.getCurrentSelectedCompanyID()+"\";$Domain=\"" + host + "\";$Path=\"" + NetConst.URL_COMPANY_FLOWERCHART_COOKIE_PATH +                "\";Max-Age=\"86400\";expires=\""+expires;//+"\";Secure;";        /**cookie*/        cookieManager.setCookie(url,uidCookie);        cookieManager.setCookie(url,cidCookie);        CookieSyncManager.getInstance().sync();    }
0 0
原创粉丝点击