okhttp3.Cookie.name()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中okhttp3.Cookie.name()方法的一些代码示例,展示了Cookie.name()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.name()方法的具体详情如下:
包路径:okhttp3.Cookie
类名称:Cookie
方法名:name

Cookie.name介绍

[英]Returns a non-empty string with this cookie's name.
[中]返回具有此cookie名称的非空字符串。

代码示例

代码示例来源:origin: square/okhttp

/** Returns a 'Cookie' HTTP request header with all cookies, like {@code a=b; c=d}. */
 private String cookieHeader(List<Cookie> cookies) {
  StringBuilder cookieHeader = new StringBuilder();
  for (int i = 0, size = cookies.size(); i < size; i++) {
   if (i > 0) {
    cookieHeader.append("; ");
   }
   Cookie cookie = cookies.get(i);
   cookieHeader.append(cookie.name()).append('=').append(cookie.value());
  }
  return cookieHeader.toString();
 }
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

@Override
public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
  List<Cookie> cookies = memoryCookies.get(url.host());
  List<Cookie> needRemove = new ArrayList<>();
  for (Cookie item : cookies) {
    if (cookie.name().equals(item.name())) {
      needRemove.add(item);
    }
  }
  cookies.removeAll(needRemove);
  cookies.add(cookie);
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

@Override
public synchronized void saveCookie(HttpUrl url, List<Cookie> cookies) {
  List<Cookie> oldCookies = memoryCookies.get(url.host());
  List<Cookie> needRemove = new ArrayList<>();
  for (Cookie newCookie : cookies) {
    for (Cookie oldCookie : oldCookies) {
      if (newCookie.name().equals(oldCookie.name())) {
        needRemove.add(oldCookie);
      }
    }
  }
  oldCookies.removeAll(needRemove);
  oldCookies.addAll(cookies);
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

public SerializableCookie(String host, Cookie cookie) {
  this.cookie = cookie;
  this.host = host;
  this.name = cookie.name();
  this.domain = cookie.domain();
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

private String getCookieToken(Cookie cookie) {
  return cookie.name() + "@" + cookie.domain();
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

private String getCookieToken(Cookie cookie) {
  return cookie.name() + "@" + cookie.domain();
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/** Returns a 'Cookie' HTTP request header with all cookies, like {@code a=b; c=d}. */
 private String cookieHeader(List<Cookie> cookies) {
  StringBuilder cookieHeader = new StringBuilder();
  for (int i = 0, size = cookies.size(); i < size; i++) {
   if (i > 0) {
    cookieHeader.append("; ");
   }
   Cookie cookie = cookies.get(i);
   cookieHeader.append(cookie.name()).append('=').append(cookie.value());
  }
  return cookieHeader.toString();
 }
}

代码示例来源:origin: biezhi/wechat-api

public String cookie(String name) {
  for (Cookie cookie : cookies()) {
    if (cookie.name().equalsIgnoreCase(name)) {
      return cookie.value();
    }
  }
  return null;
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

private void writeObject(ObjectOutputStream out) throws IOException {
  out.defaultWriteObject();
  out.writeObject(cookie.name());
  out.writeObject(cookie.value());
  out.writeLong(cookie.expiresAt());
  out.writeObject(cookie.domain());
  out.writeObject(cookie.path());
  out.writeBoolean(cookie.secure());
  out.writeBoolean(cookie.httpOnly());
  out.writeBoolean(cookie.hostOnly());
  out.writeBoolean(cookie.persistent());
}

代码示例来源:origin: seven332/EhViewer

public Key(Cookie cookie) {
 this.name = cookie.name();
 this.domain = cookie.domain();
 this.path = cookie.path();
}

代码示例来源:origin: seven332/EhViewer

public boolean contains(HttpUrl url, String name) {
 for (Cookie cookie : getCookies(url)) {
  if (ObjectUtils.equal(cookie.name(), name)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: seven332/EhViewer

@Override
  public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = super.loadForRequest(url);

    boolean checkTips = domainMatch(url, EhUrl.DOMAIN_E);

    if (checkTips) {
      List<Cookie> result = new ArrayList<>(cookies.size() + 1);
      // Add all but skip some
      for (Cookie cookie: cookies) {
        String name = cookie.name();
        if (EhConfig.KEY_CONTENT_WARNING.equals(name)) {
          continue;
        }
        if (EhConfig.KEY_UCONFIG.equals(name)) {
          continue;
        }
        result.add(cookie);
      }
      // Add some
      result.add(sTipsCookie);
      return Collections.unmodifiableList(result);
    } else {
      return cookies;
    }
  }
}

代码示例来源:origin: GitLqr/LQRWeChat

@Override
  public int hashCode() {
    int hash = 17;
    hash = 31 * hash + cookie.name().hashCode();
    hash = 31 * hash + cookie.domain().hashCode();
    hash = 31 * hash + cookie.path().hashCode();
    hash = 31 * hash + (cookie.secure() ? 0 : 1);
    hash = 31 * hash + (cookie.hostOnly() ? 0 : 1);
    return hash;
  }
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
  Map<String, String> map = new LinkedHashMap<>();
  if (cookies != null) {
    for (Cookie c : cookies) {
      if (c != null && c.name() != null && c.value() != null) {
        map.put(c.name(), StringUtil.get(c.value()));
      }
    }
  }
  saveCookie(url == null ? null : url.host(), JSON.toJSONString(map));//default constructor not found  cookies));
}

代码示例来源:origin: seven332/EhViewer

public ContentValues toContentValues(Cookie cookie) {
 ContentValues contentValues = new ContentValues(9);
 contentValues.put(COLUMN_NAME, cookie.name());
 contentValues.put(COLUMN_VALUE, cookie.value());
 contentValues.put(COLUMN_EXPIRES_AT, cookie.expiresAt());
 contentValues.put(COLUMN_DOMAIN, cookie.domain());
 contentValues.put(COLUMN_PATH, cookie.path());
 contentValues.put(COLUMN_SECURE, cookie.secure());
 contentValues.put(COLUMN_HTTP_ONLY, cookie.httpOnly());
 contentValues.put(COLUMN_PERSISTENT, cookie.persistent());
 contentValues.put(COLUMN_HOST_ONLY, cookie.hostOnly());
 return contentValues;
}

代码示例来源:origin: GitLqr/LQRWeChat

private void writeObject(ObjectOutputStream out) throws IOException {
  out.writeObject(cookie.name());
  out.writeObject(cookie.value());
  out.writeLong(cookie.persistent() ? cookie.expiresAt() : NON_VALID_EXPIRES_AT);
  out.writeObject(cookie.domain());
  out.writeObject(cookie.path());
  out.writeBoolean(cookie.secure());
  out.writeBoolean(cookie.httpOnly());
  out.writeBoolean(cookie.hostOnly());
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

/** 根据url移除当前的cookie */
@Override
public synchronized boolean removeCookie(HttpUrl url, Cookie cookie) {
  if (!cookies.containsKey(url.host())) return false;
  String cookieToken = getCookieToken(cookie);
  if (!cookies.get(url.host()).containsKey(cookieToken)) return false;
  //内存移除
  cookies.get(url.host()).remove(cookieToken);
  //数据库移除
  String whereClause = "host=? and name=? and domain=?";
  String[] whereArgs = {url.host(), cookie.name(), cookie.domain()};
  CookieManager.getInstance().delete(whereClause, whereArgs);
  return true;
}

代码示例来源:origin: GitLqr/LQRWeChat

@Override
public boolean equals(Object other) {
  if (!(other instanceof IdentifiableCookie)) return false;
  IdentifiableCookie that = (IdentifiableCookie) other;
  return that.cookie.name().equals(this.cookie.name())
      && that.cookie.domain().equals(this.cookie.domain())
      && that.cookie.path().equals(this.cookie.path())
      && that.cookie.secure() == this.cookie.secure()
      && that.cookie.hostOnly() == this.cookie.hostOnly();
}

代码示例来源:origin: GitLqr/LQRWeChat

private static String createCookieKey(Cookie cookie) {
  return (cookie.secure() ? "https" : "http") + "://" + cookie.domain() + cookie.path() + "|" + cookie.name();
}

代码示例来源:origin: seven332/EhViewer

private Cookie longLive(Cookie cookie) {
 return new Cookie.Builder()
   .name(cookie.name())
   .value(cookie.value())
   .domain(cookie.domain())
   .path(cookie.path())
   .expiresAt(Long.MAX_VALUE)
   .build();
}

相关文章