Search in sources :

Example 16 with Cookie

use of com.firenio.codec.http11.Cookie in project AndroidFrame by tongxiaoyun.

the class SharedPrefsCookiePersistor method removeAll.

@Override
public void removeAll(Collection<Cookie> cookies) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    for (Cookie cookie : cookies) {
        editor.remove(createCookieKey(cookie));
    }
    editor.commit();
}
Also used : Cookie(okhttp3.Cookie) SharedPreferences(android.content.SharedPreferences)

Example 17 with Cookie

use of com.firenio.codec.http11.Cookie in project Atom_Android by Rogrand-Dev.

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 = ((OkHttpCookies) objectInputStream.readObject()).getCookies();
    } catch (IOException e) {
        Log.d(TAG, "IOException in decodeCookie", e);
    } catch (ClassNotFoundException e) {
        Log.d(TAG, "ClassNotFoundException in decodeCookie", e);
    }
    return cookie;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 18 with Cookie

use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method getCookie.

@OnClick(R.id.getCookie)
public void getCookie(View view) {
    // 一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
    List<Cookie> cookies = cookieStore.getCookie(httpUrl);
    showToast(httpUrl.host() + "对应的cookie如下:" + cookies.toString());
}
Also used : Cookie(okhttp3.Cookie) CookieStore(com.lzy.okgo.cookie.store.CookieStore) HttpUrl(okhttp3.HttpUrl) OnClick(butterknife.OnClick)

Example 19 with Cookie

use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method getAllCookie.

@OnClick(R.id.getAllCookie)
public void getAllCookie(View view) {
    // 一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    List<Cookie> allCookie = cookieStore.getAllCookie();
    showToast("所有cookie如下:" + allCookie.toString());
}
Also used : Cookie(okhttp3.Cookie) CookieStore(com.lzy.okgo.cookie.store.CookieStore) OnClick(butterknife.OnClick)

Example 20 with Cookie

use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.

the class SerializableCookie method bytesToCookie.

public static Cookie bytesToCookie(byte[] bytes) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    Cookie cookie = null;
    try {
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableCookie) objectInputStream.readObject()).getCookie();
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    }
    return cookie;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Cookie (okhttp3.Cookie)102 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)20 HttpUrl (okhttp3.HttpUrl)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ObjectInputStream (java.io.ObjectInputStream)16 SharedPreferences (android.content.SharedPreferences)12 Context (android.content.Context)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Test (org.junit.Test)8 Response (okhttp3.Response)7 SerializableCookie (com.lzy.okgo.cookie.SerializableCookie)6 Request (okhttp3.Request)6 SuppressLint (android.annotation.SuppressLint)4 CookieManager (android.webkit.CookieManager)4 EhCookieStore (com.hippo.ehviewer.client.EhCookieStore)4 OnClick (butterknife.OnClick)3 SerializableCookie (com.franmontiel.persistentcookiejar.persistence.SerializableCookie)3