保存cookie
List
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
String[] keyValueSets = CookieManager.getInstance().getCookie(domain).split(";");
for(String cookie : keyValueSets) {
String[] keyValue = cookie.split("=");
String key = keyValue[0];
String value = "";
if(keyValue.length>1) value = keyValue[1];
BasicClientCookie baseCookie = new BasicClientCookie(key, value);
baseCookie.setDomain(domain);
httpClient.getCookieStore().addCookie(baseCookie);
}