use of okhttp3.Cookie in project OkHttp3 by MrZhousf.
the class SerializableCookie method decode.
public Cookie decode(String encodedCookie) {
byte[] bytes = hexStringToByteArray(encodedCookie);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
ObjectInputStream objectInputStream = null;
try {
objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableCookie) objectInputStream.readObject()).cookie;
} catch (IOException e) {
Log.d(TAG, "IOException in decodeCookie", e);
} catch (ClassNotFoundException e) {
Log.d(TAG, "ClassNotFoundException in decodeCookie", e);
} finally {
if (objectInputStream != null) {
try {
objectInputStream.close();
} catch (IOException e) {
Log.d(TAG, "Stream not closed in decodeCookie", e);
}
}
}
return cookie;
}
use of okhttp3.Cookie in project JustAndroid by chinaltz.
the class PersistentCookieStore method decodeCookie.
/**
* 将字符串反序列化成cookies
*
* @param cookieString cookies string
* @return cookie object
*/
protected Cookie decodeCookie(String cookieString) {
byte[] bytes = hexStringToByteArray(cookieString);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableOkHttpCookies) objectInputStream.readObject()).getCookies();
} catch (IOException e) {
Log.d(LOG_TAG, "IOException in decodeCookie", e);
} catch (ClassNotFoundException e) {
Log.d(LOG_TAG, "ClassNotFoundException in decodeCookie", e);
}
return cookie;
}
use of okhttp3.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.post(Urls.URL_TEXT_UPLOAD).tag(//
this).execute(new StringDialogCallback(this) {
@Override
public void onSuccess(String s, Call call, Response response) {
handleResponse(s, call, response);
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
handleError(call, response);
}
});
}
use of okhttp3.Cookie in project okhttp-OkGo by jeasonlzy.
the class MemoryCookieStore method saveCookie.
@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);
}
use of okhttp3.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);
}
Aggregations