Search in sources :

Example 56 with Cookie

use of com.firenio.codec.http11.Cookie in project MiMangaNu by raulhaag.

the class BatoTo method testLogin.

// just log in batoto to store the cookie if all ok
@Override
public boolean testLogin(String user, String password) throws Exception {
    Navigator nav = getNavigatorAndFlushParameters();
    CookieJar ccj = nav.getHttpClient().cookieJar();
    VolatileCookieJar cj = new VolatileCookieJar();
    nav.setCookieJar(cj);
    String data = nav.get(HOST + "/forums/index.php?app=core&module=global&section=login");
    HashMap<String, String> params = Navigator.getFormParamsFromSource(data);
    nav = getNavigatorAndFlushParameters();
    nav.addPost("auth_key", params.get("auth_key"));
    nav.addPost("ips_password", password);
    nav.addPost("ips_username", user);
    nav.addPost("referer", "https://bato.to/forums/");
    nav.addPost("rememberMe", "1");
    nav.post(HOST + "/forums/index.php?app=core&module=global&section=login&do=process");
    List<Cookie> cookies = Navigator.getCookieJar().loadForRequest(HttpUrl.parse("https://bato.to"));
    nav.setCookieJar(ccj);
    return cj.contain("member_id");
}
Also used : Cookie(okhttp3.Cookie) Navigator(ar.rulosoft.navegadores.Navigator) VolatileCookieJar(ar.rulosoft.navegadores.VolatileCookieJar) CookieJar(okhttp3.CookieJar) VolatileCookieJar(ar.rulosoft.navegadores.VolatileCookieJar)

Example 57 with Cookie

use of com.firenio.codec.http11.Cookie in project MVPFrames by RockyQu.

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;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 58 with Cookie

use of com.firenio.codec.http11.Cookie in project MVPFrames by RockyQu.

the class SharedPrefsCookiePersistor method saveAll.

@Override
public void saveAll(Collection<Cookie> cookies) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    for (Cookie cookie : cookies) {
        editor.putString(createCookieKey(cookie), new SerializableCookie().encode(cookie));
    }
    editor.commit();
}
Also used : Cookie(okhttp3.Cookie) SharedPreferences(android.content.SharedPreferences)

Example 59 with Cookie

use of com.firenio.codec.http11.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;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 60 with Cookie

use of com.firenio.codec.http11.Cookie in project apps-android-wikipedia by wikimedia.

the class SharedPreferenceCookieManager method buildCookieList.

private void buildCookieList(@NonNull List<Cookie> outList, @NonNull List<Cookie> inList, @Nullable String prefix) {
    Iterator<Cookie> i = inList.iterator();
    boolean cookieJarModified = false;
    while (i.hasNext()) {
        Cookie cookie = i.next();
        if (prefix != null && !cookie.name().startsWith(prefix)) {
            continue;
        }
        // But wait, is the cookie expired?
        if (cookie.expiresAt() < System.currentTimeMillis()) {
            i.remove();
            cookieJarModified = true;
        } else {
            outList.add(cookie);
        }
    }
    if (cookieJarModified) {
        persistCookies();
    }
}
Also used : Cookie(okhttp3.Cookie)

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