Search in sources :

Example 46 with Cookie

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

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);
}
Also used : Cookie(okhttp3.Cookie)

Example 47 with Cookie

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

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);
    }
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Example 48 with Cookie

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

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;
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) ArrayList(java.util.ArrayList)

Example 49 with Cookie

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

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);
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList)

Example 50 with Cookie

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

the class KissManga method chapterInit.

@Override
public synchronized void chapterInit(Chapter chapter) throws Exception {
    if (chapter.getPages() == 0) {
        int pages = 0;
        Response response = Navigator.getInstance().getResponse(HOST + chapter.getPath());
        String source = response.body().string();
        if (source.contains("class=\"g-recaptcha\"")) {
            throw new Exception(context.getString(R.string.server_uses_captcha));
        // Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(HOST + chapter.getPath()));
        // context.startActivity(browserIntent);
        }
        if (source.contains("this captcha")) {
            if (RequestWebViewUserAction.isRequestAvailable()) {
                List<Cookie> cookies = Navigator.getCookieJar().loadForRequest(HttpUrl.parse(HOST + chapter.getPath()));
                StringBuilder sb = new StringBuilder();
                for (Cookie cookie : cookies) {
                    sb.append(cookie.name()).append("=").append(cookie.value()).append(";");
                }
                RequestWebViewUserAction.makeRequest(response.request().url().toString(), null, source.replaceAll("\"\\/\\/ads.+?\"", "").replaceAll("<.script>\\s<.div>\\s(<[\\s\\S]+?)<div id=\"footer\">", ""));
                chapterInit(chapter);
                return;
            } else {
                throw new Exception("User action required but unavailable");
            }
        }
        String ca = getNavigatorAndFlushParameters().get(HOST + "/Scripts/ca.js");
        String lo = getNavigatorAndFlushParameters().get(HOST + "/Scripts/lo.js");
        try {
            Duktape duktape = Duktape.create();
            duktape.evaluate(ca);
            duktape.evaluate(lo);
            Pattern p = Pattern.compile("javascript\">(.+?)<", Pattern.DOTALL);
            Matcher m = p.matcher(source);
            while (m.find()) {
                if (m.group(1).contains("CryptoJS")) {
                    duktape.evaluate(m.group(1));
                }
            }
            p = Pattern.compile("lstOLA.push\\((wrap.+?\\))\\)", Pattern.DOTALL);
            m = p.matcher(source);
            StringBuilder sb = new StringBuilder();
            String image;
            while (m.find()) {
                pages++;
                image = (String) duktape.evaluate(m.group(1) + ".toString()");
                sb.append("|").append(image);
            }
            chapter.setExtra(sb.toString());
        } catch (Exception ignored) {
        }
        chapter.setPages(pages);
    }
}
Also used : Response(okhttp3.Response) Cookie(okhttp3.Cookie) Pattern(java.util.regex.Pattern) Duktape(com.squareup.duktape.Duktape) Matcher(java.util.regex.Matcher)

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