(如所承诺的解决了这一点。我还是不喜欢它,感觉我错过了这样做的“正确”的方式,但是,它的工作原理。)
您可以使用
cookieManager注册您的cookies(并因此使应用程序之间提供这些cookie),用下面的代码:
将cookie保存到中
cookieManager:
List<cookie> cookies = httpClient.getcookieStore().getcookies();if(cookies != null){ for(cookie cookie : cookies) { String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain(); cookieManager.getInstance().setcookie(cookie.getDomain(), cookieString); }}cookieSyncManager.getInstance().sync();
检查指定域的cookie:
if(cookieManager.getInstance().getcookie(URI_FOR_DOMAIN)
要为HttpClient的重建值:
DefaultHttpClient httpClient = new DefaultHttpClient(params);String[] keyValueSets = cookieManager.getInstance().getcookie(URI_FOR_DOMAIN).split(";");for(String cookie : keyValueSets){ String[] keyValue = cookie.split("="); String key = keyValue[0]; String value = ""; if(keyValue.length>1) value = keyValue[1]; httpClient.getcookieStore().addcookie(new BasicClientcookie(key, value));}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)