Search in sources :

Example 76 with Cookie

use of com.firenio.codec.http11.Cookie in project WanAndroid by dangxy.

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 77 with Cookie

use of com.firenio.codec.http11.Cookie in project WanAndroid by dangxy.

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 78 with Cookie

use of com.firenio.codec.http11.Cookie in project BaseProject by wareine.

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 79 with Cookie

use of com.firenio.codec.http11.Cookie in project Auto.js by hyb1996.

the class WebkitCookieManagerProxy method loadForRequest.

@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    ArrayList<Cookie> cookieArrayList = new ArrayList<>();
    try {
        Map<String, List<String>> cookieList = get(url.uri(), new HashMap<String, List<String>>());
        // Format here looks like: "Cookie":["cookie1=val1;cookie2=val2;"]
        for (List<String> ls : cookieList.values()) {
            for (String s : ls) {
                String[] cookies = s.split(";");
                for (String cookie : cookies) {
                    Cookie c = Cookie.parse(url, cookie);
                    cookieArrayList.add(c);
                }
            }
        }
    } catch (IOException e) {
        Log.e(TAG, "error making cookie!", e);
    }
    return cookieArrayList;
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 80 with Cookie

use of com.firenio.codec.http11.Cookie in project Auto.js by hyb1996.

the class WebkitCookieManagerProxy method saveFromResponse.

@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
    HashMap<String, List<String>> generatedResponseHeaders = new HashMap<>();
    ArrayList<String> cookiesList = new ArrayList<>();
    for (Cookie c : cookies) {
        // toString correctly generates a normal cookie string
        cookiesList.add(c.toString());
    }
    generatedResponseHeaders.put("Set-Cookie", cookiesList);
    try {
        put(url.uri(), generatedResponseHeaders);
    } catch (IOException e) {
        Log.e(TAG, "Error adding cookies through okhttp", e);
    }
}
Also used : Cookie(okhttp3.Cookie) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

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