use of com.firenio.codec.http11.Cookie in project MiMangaNu by raulhaag.
the class RequestWebViewUserAction method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
String web = bundle.getString(WEB_TAG);
String headers = null, body = null;
if (bundle.containsKey(HEADERS_TAG)) {
headers = bundle.getString(HEADERS_TAG);
}
if (bundle.containsKey(BODY_TAG)) {
body = bundle.getString(BODY_TAG);
}
setContentView(R.layout.activity_request_webview_user_action);
WebView wv = findViewById(R.id.webView);
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
RequestWebViewUserAction.this.runOnUiThread(() -> {
lastCookie = CookieManager.getInstance().getCookie(web);
onBackPressed();
});
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (url.contains("__cf_chl_captcha_tk__")) {
lastCookie = CookieManager.getInstance().getCookie(web);
onBackPressed();
}
}
});
wv.getSettings().setUserAgentString(Navigator.USER_AGENT);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
wv.getSettings().setDisplayZoomControls(true);
CookieManager cm = CookieManager.getInstance();
cm.removeAllCookie();
HttpUrl url = HttpUrl.parse(web);
List<Cookie> actCookies = Navigator.getCookieJar().loadForRequest(url);
cm.setCookie(url.host(), "__cfduid=");
for (Cookie c : actCookies) {
cm.setCookie(url.host(), c.name() + "=" + c.value());
}
wv.getSettings().setJavaScriptEnabled(true);
HashMap<String, String> headMap = new HashMap<>();
headMap.put("Referer", web);
if (body != null) {
wv.loadDataWithBaseURL(web, body, null, null, null);
} else {
wv.loadUrl(web, headMap);
}
}
use of com.firenio.codec.http11.Cookie in project MiMangaNu by raulhaag.
the class CFInterceptor method addWebViewCookiesToNavigator.
public void addWebViewCookiesToNavigator(String url) {
cookies = CookieManager.getInstance().getCookie(url);
String[] cks = cookies.split(";");
ArrayList<Cookie> cookieArrayList = new ArrayList<>();
HttpUrl url1 = HttpUrl.parse(url);
url1 = HttpUrl.parse((url1.isHttps() ? "https://" : "http://") + url1.host());
for (String c : cks) {
cookieArrayList.add(Cookie.parse(url1, c + "; Max-Age=36000000; domain=" + removeSubDomains(url1.host())));
}
Navigator.getInstance().getHttpClient().cookieJar().saveFromResponse(url1, cookieArrayList);
}
use of com.firenio.codec.http11.Cookie in project ForPDA by RadiationX.
the class App method initImageLoader.
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).imageDownloader(new BaseImageDownloader(context) {
final Pattern pattern4pda = Pattern.compile("(?:http?s?:)?\\/\\/.*?4pda\\.(?:ru|to)");
@Override
public InputStream getStream(String imageUri, Object extra) throws IOException {
if (imageUri.substring(0, 2).equals("//"))
imageUri = "http:".concat(imageUri);
Log.d(App.class.getSimpleName(), "ImageLoader getStream " + imageUri);
return super.getStream(imageUri, extra);
}
@Override
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
HttpURLConnection conn = super.createConnection(url, extra);
if (pattern4pda.matcher(url).find()) {
Map<String, Cookie> cookies = App.get().Di().getWebClient().getClientCookies();
String stringCookies = "";
for (Map.Entry<String, Cookie> cookieEntry : cookies.entrySet()) {
stringCookies = stringCookies.concat(cookieEntry.getKey()).concat("=").concat(cookieEntry.getValue().value()).concat(";");
}
conn.setRequestProperty("Cookie", stringCookies);
}
return conn;
}
}).threadPoolSize(5).threadPriority(Thread.MIN_PRIORITY).denyCacheImageMultipleSizesInMemory().memoryCache(// 5 Mb
new UsingFreqLimitedMemoryCache(5 * 1024 * 1024)).diskCacheFileNameGenerator(new HashCodeFileNameGenerator()).defaultDisplayImageOptions(options.build()).build();
ImageLoader.getInstance().init(config);
}
use of com.firenio.codec.http11.Cookie in project okhttp-OkGo by jeasonlzy.
the class PersistentCookieStore method decodeCookie.
/**
* 将字符串反序列化成cookies
*
* @param cookieString cookies string
* @return cookie object
*/
private Cookie decodeCookie(String cookieString) {
byte[] bytes = hexStringToByteArray(cookieString);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
} 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 com.firenio.codec.http11.Cookie in project okhttputils by hongyangAndroid.
the class PersistentCookieStore method decodeCookie.
protected Cookie decodeCookie(String cookieString) {
byte[] bytes = hexStringToByteArray(cookieString);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
} catch (IOException e) {
Log.d(LOG_TAG, "IOException in decodeCookie", e);
} catch (ClassNotFoundException e) {
Log.d(LOG_TAG, "ClassNotFoundException in decodeCookie", e);
}
return cookie;
}
Aggregations