@weidong
2017-10-22T02:49:50.000000Z
字数 662
阅读 380
工具类
public class CookieUtils {
/**
* 编码
*/
public static String encodeBase64(String cookieStr) {
try {
cookieStr = new String(Base64.encodeBase64(cookieStr
.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return cookieStr;
}
/**
* 解码
*/
public static String decodeBase64(String cookieStr) {
try {
cookieStr = new String(Base64.decodeBase64(cookieStr.getBytes()),
"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cookieStr;
}
/**
* 获取指定Cookie的值
*/
public static Cookie getCookieByName(Cookie[] cs, String name) {
if (cs == null || cs.length == 0) {
return null;
}
for (Cookie c : cs) {
if (c.getName().equals(name)) {
return c;
}
}
return null;
}
}