本文整理了Java中okhttp3.Cookie
类的一些代码示例,展示了Cookie
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie
类的具体详情如下:
包路径:okhttp3.Cookie
类名称:Cookie
[英]An RFC 6265 Cookie.
This class doesn't support additional attributes on cookies, like Chromium's Priority=HIGH extension.
[中][RFC 6265](http://tools.ietf.org/html/rfc6265)Cookie。
此类不支持cookie上的附加属性,如Chromium's Priority=HIGH extension。
代码示例来源: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: square/okhttp
@Override public String toString() {
return toString(false);
}
代码示例来源: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: 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: seven332/EhViewer
public Key(Cookie cookie) {
this.name = cookie.name();
this.domain = cookie.domain();
this.path = cookie.path();
}
代码示例来源:origin: GitLqr/LQRWeChat
private static String createCookieKey(Cookie cookie) {
return (cookie.secure() ? "https" : "http") + "://" + cookie.domain() + cookie.path() + "|" + cookie.name();
}
代码示例来源:origin: marklogic/java-client-api
public static ClientCookie parse(HttpUrl url, String setCookie) {
Cookie cookie = Cookie.parse(url, setCookie);
if(cookie == null) throw new IllegalStateException(setCookie + "is not a well-formed cookie");
return new ClientCookie(cookie.name(), cookie.value(), cookie.expiresAt(), cookie.domain(), cookie.path(),
cookie.secure());
}
代码示例来源: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();
}
代码示例来源: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: ViDA-NYU/ache
@Test
public void testOkHttpCookielInput() {
cookie.setDomain(".slides.com");
okhttp3.Cookie resultCookie = CookieUtils.asOkhttp3Cookie(cookie);
assertTrue(resultCookie.name().equals("key1"));
assertTrue(resultCookie.value().equals("value1"));
assertTrue(resultCookie.domain().equals("slides.com"));
}
代码示例来源:origin: seven332/EhViewer
Cookie toRemove = null;
CookieSet set = map.get(cookie.domain());
if (set == null) {
set = new CookieSet();
map.put(cookie.domain(), set);
if (cookie.expiresAt() <= System.currentTimeMillis()) {
toRemove = set.remove(cookie);
if (toRemove != null && !toRemove.persistent()) {
toRemove = null;
toUpdate = set.add(cookie);
if (!toAdd.persistent()) toAdd = null;
if (toUpdate != null && !toUpdate.persistent()) toUpdate = null;
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 当前cookie是否过期 */
private static boolean isCookieExpired(Cookie cookie) {
return cookie.expiresAt() < System.currentTimeMillis();
}
代码示例来源:origin: schildbach/public-transport-enabler
request.header("Referer", referer);
final Cookie sessionCookie = this.sessionCookie;
if (sessionCookie != null && sessionCookie.name().equals(sessionCookieName))
request.header("Cookie", sessionCookie.toString());
final List<Cookie> cookies = Cookie.parseAll(url, response.headers());
for (final Iterator<Cookie> i = cookies.iterator(); i.hasNext();) {
final Cookie cookie = i.next();
if (cookie.name().equals(sessionCookieName)) {
this.sessionCookie = cookie;
break;
代码示例来源:origin: GitLqr/LQRWeChat
private static List<Cookie> filterPersistentCookies(List<Cookie> cookies) {
List<Cookie> persistentCookies = new ArrayList<>();
for (Cookie cookie : cookies) {
if (cookie.persistent()) {
persistentCookies.add(cookie);
}
}
return persistentCookies;
}
代码示例来源:origin: seven332/EhViewer
/**
* Get cookies for the url. Fill {@code accepted} and {@code expired}.
*/
public void get(HttpUrl url, List<Cookie> accepted, List<Cookie> expired) {
long now = System.currentTimeMillis();
Iterator<Map.Entry<Key, Cookie>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Cookie cookie = iterator.next().getValue();
if (cookie.expiresAt() <= now) {
iterator.remove();
expired.add(cookie);
} else if (cookie.matches(url)) {
accepted.add(cookie);
}
}
}
代码示例来源:origin: jruesga/rview
private String value(String name) {
if (mCookieStore.containsKey(name)) {
return mCookieStore.get(name).value();
}
return null;
}
代码示例来源:origin: FussenYu/MVP_Project
private static List<Cookie> filterPersistentCookies(List<Cookie> cookies) {
List<Cookie> persistentCookies = new ArrayList<>();
for (Cookie cookie : cookies) {
Log.i(TAG,"=====cookie===="+ cookie.toString());
if (cookie.persistent()) {
persistentCookies.add(cookie);
}
}
return persistentCookies;
}
代码示例来源:origin: seven332/EhViewer
@Override
public int compare(Cookie o1, Cookie o2) {
return o2.path().length() - o1.path().length();
}
});
代码示例来源:origin: seven332/EhViewer
CookieSet set = map.get(cookie.domain());
if (set == null) {
set = new CookieSet();
map.put(cookie.domain(), set);
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!