[关闭]
@weidong 2017-10-22T02:49:50.000000Z 字数 662 阅读 380

CookieUtils

工具类


  1. public class CookieUtils {
  2. /**
  3. * 编码
  4. */
  5. public static String encodeBase64(String cookieStr) {
  6. try {
  7. cookieStr = new String(Base64.encodeBase64(cookieStr
  8. .getBytes("UTF-8")));
  9. } catch (UnsupportedEncodingException e) {
  10. e.printStackTrace();
  11. }
  12. return cookieStr;
  13. }
  14. /**
  15. * 解码
  16. */
  17. public static String decodeBase64(String cookieStr) {
  18. try {
  19. cookieStr = new String(Base64.decodeBase64(cookieStr.getBytes()),
  20. "UTF-8");
  21. } catch (UnsupportedEncodingException e) {
  22. // TODO Auto-generated catch block
  23. e.printStackTrace();
  24. }
  25. return cookieStr;
  26. }
  27. /**
  28. * 获取指定Cookie的值
  29. */
  30. public static Cookie getCookieByName(Cookie[] cs, String name) {
  31. if (cs == null || cs.length == 0) {
  32. return null;
  33. }
  34. for (Cookie c : cs) {
  35. if (c.getName().equals(name)) {
  36. return c;
  37. }
  38. }
  39. return null;
  40. }
  41. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注