Fix bug
This commit is contained in:
parent
4d8669d01d
commit
df055f8ae2
|
|
@ -33,7 +33,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
//Debug For HTTP/3
|
//Debug For HTTP/3
|
||||||
//implementation 'org.chromium.net:cronet-embedded:108.5359.79'
|
//implementation 'com.google.android.gms:play-services-cronet:18.0.1'
|
||||||
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
|
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
|
||||||
implementation 'androidx.annotation:annotation:1.5.0'
|
implementation 'androidx.annotation:annotation:1.5.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
|
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
package com.github.catvod.net;
|
||||||
|
|
||||||
|
import com.github.catvod.crawler.Spider;
|
||||||
|
import com.github.catvod.spider.Init;
|
||||||
|
import com.google.net.cronet.okhttptransport.CronetInterceptor;
|
||||||
|
|
||||||
|
import org.chromium.net.CronetEngine;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import okhttp3.Dns;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
|
public class Cronet {
|
||||||
|
|
||||||
|
public static final String POST = "POST";
|
||||||
|
public static final String GET = "GET";
|
||||||
|
|
||||||
|
private final OkHttpClient noRedirect;
|
||||||
|
private final OkHttpClient client;
|
||||||
|
|
||||||
|
private static class Loader {
|
||||||
|
static volatile Cronet INSTANCE = new Cronet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Cronet get() {
|
||||||
|
return Loader.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cronet() {
|
||||||
|
client = getBuilder().build();
|
||||||
|
noRedirect = client.newBuilder().followRedirects(false).followSslRedirects(false).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private OkHttpClient.Builder getBuilder() {
|
||||||
|
OkHttpClient.Builder builder = OkHttp.getBuilder();
|
||||||
|
addInterceptor(builder);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addInterceptor(OkHttpClient.Builder builder) {
|
||||||
|
try {
|
||||||
|
builder.addInterceptor(CronetInterceptor.newBuilder(new CronetEngine.Builder(Init.context()).build()).build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OkHttpClient client() {
|
||||||
|
return get().client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OkHttpClient noRedirect() {
|
||||||
|
return get().noRedirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dns safeDns() {
|
||||||
|
try {
|
||||||
|
return (Dns) Spider.class.getMethod("safeDns").invoke(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Dns.SYSTEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stringNoRedirect(String url, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
string(noRedirect(), GET, url, null, null, header, respHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(OkHttpClient client, String method, String url, String tag, Map<String, String> params, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
return new OkRequest(method, url, params, header, respHeader).tag(tag).execute(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url) {
|
||||||
|
return string(url, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url, Map<String, String> header) {
|
||||||
|
return string(url, header, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
return string(url, null, header, respHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url, Map<String, String> params, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
return string(url, null, params, header, respHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url, String tag, Map<String, String> header) {
|
||||||
|
return string(url, tag, null, header, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String string(String url, String tag, Map<String, String> params, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
return string(client(), GET, url, tag, params, header, respHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String url, Map<String, String> params) {
|
||||||
|
return post(url, params, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String url, Map<String, String> params, Map<String, String> header) {
|
||||||
|
return post(url, params, header, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String url, Map<String, String> params, Map<String, String> header, Map<String, List<String>> respHeader) {
|
||||||
|
return string(client(), POST, url, null, params, header, respHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postJson(String url, String json) {
|
||||||
|
return postJson(url, json, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postJson(String url, String json, Map<String, String> header) {
|
||||||
|
return new OkRequest(POST, url, json, header).execute(client());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRedirectLocation(Map<String, List<String>> headers) {
|
||||||
|
if (headers == null) return null;
|
||||||
|
if (headers.containsKey("location")) return headers.get("location").get(0);
|
||||||
|
if (headers.containsKey("Location")) return headers.get("Location").get(0);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
package com.github.catvod.net;
|
package com.github.catvod.net;
|
||||||
|
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.spider.Init;
|
|
||||||
import com.google.net.cronet.okhttptransport.CronetInterceptor;
|
|
||||||
|
|
||||||
import org.chromium.net.CronetEngine;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -35,8 +31,8 @@ public class OkHttp {
|
||||||
noRedirect = client.newBuilder().followRedirects(false).followSslRedirects(false).build();
|
noRedirect = client.newBuilder().followRedirects(false).followSslRedirects(false).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient.Builder getBuilder() {
|
public static OkHttpClient.Builder getBuilder() {
|
||||||
return new OkHttpClient.Builder().dns(safeDns()).addInterceptor(CronetInterceptor.newBuilder(new CronetEngine.Builder(Init.context()).build()).build()).callTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).retryOnConnectionFailure(true).hostnameVerifier(SSLSocketFactoryCompat.hostnameVerifier).sslSocketFactory(new SSLSocketFactoryCompat(), SSLSocketFactoryCompat.trustAllCert);
|
return new OkHttpClient.Builder().dns(safeDns()).callTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).retryOnConnectionFailure(true).hostnameVerifier(SSLSocketFactoryCompat.hostnameVerifier).sslSocketFactory(new SSLSocketFactoryCompat(), SSLSocketFactoryCompat.trustAllCert);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OkHttpClient client() {
|
private static OkHttpClient client() {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
281195ff29b564bd774323e1cab13017
|
945b391d7430796229f6d5309037abeb
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue