use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class MemoryCookieStore method saveCookie.
@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);
}
use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class SPCookieStore method loadCookie.
/**
* 根据当前url获取所有需要的cookie,只返回没有过期的cookie
*/
@Override
public synchronized List<Cookie> loadCookie(HttpUrl url) {
List<Cookie> ret = new ArrayList<>();
if (!cookies.containsKey(url.host()))
return ret;
Collection<Cookie> urlCookies = cookies.get(url.host()).values();
for (Cookie cookie : urlCookies) {
if (isCookieExpired(cookie)) {
removeCookie(url, cookie);
} else {
ret.add(cookie);
}
}
return ret;
}
use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class SerializableCookie method parseCursorToBean.
public static SerializableCookie parseCursorToBean(Cursor cursor) {
String host = cursor.getString(cursor.getColumnIndex(HOST));
byte[] cookieBytes = cursor.getBlob(cursor.getColumnIndex(COOKIE));
Cookie cookie = bytesToCookie(cookieBytes);
return new SerializableCookie(host, cookie);
}
use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class DBCookieStore method saveCookie.
@Override
public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
if (!cookies.containsKey(url.host())) {
cookies.put(url.host(), new ConcurrentHashMap<String, Cookie>());
}
// 当前cookie是否过期
if (isCookieExpired(cookie)) {
removeCookie(url, cookie);
} else {
// 内存缓存
cookies.get(url.host()).put(getCookieToken(cookie), cookie);
// 数据库缓存
SerializableCookie serializableCookie = new SerializableCookie(url.host(), cookie);
CookieManager.getInstance().replace(serializableCookie);
}
}
use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method addCookie.
@OnClick(R.id.addCookie)
public void addCookie(View view) {
HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
Cookie.Builder builder = new Cookie.Builder();
Cookie cookie = builder.name("myCookieKey1").value("myCookieValue1").domain(httpUrl.host()).build();
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
cookieStore.saveCookie(httpUrl, cookie);
showToast("详细添加cookie的代码,请看demo的代码");
//
OkGo.<String>post(Urls.URL_TEXT_UPLOAD).tag(//
this).execute(new StringDialogCallback(this) {
@Override
public void onSuccess(Response<String> response) {
handleResponse(response);
}
@Override
public void onError(Response<String> response) {
handleError(response);
}
});
}
Aggregations