This commit is contained in:
jhengazuki 2025-08-06 14:12:10 +08:00
parent 5f31a3d442
commit 71ae952b74
3 changed files with 8 additions and 14 deletions

View File

@ -37,18 +37,10 @@ public class OkHttp {
return Loader.INSTANCE; return Loader.INSTANCE;
} }
public static Response newCall(Request request) throws IOException {
return client().newCall(request).execute();
}
public static Response newCall(String url) throws IOException { public static Response newCall(String url) throws IOException {
return client().newCall(new Request.Builder().url(url).build()).execute(); return client().newCall(new Request.Builder().url(url).build()).execute();
} }
public static Response newCall(String url, Map<String, String> header) throws IOException {
return client().newCall(new Request.Builder().url(url).headers(Headers.of(header)).build()).execute();
}
public static String string(String url) { public static String string(String url) {
return string(url, null); return string(url, null);
} }
@ -58,7 +50,7 @@ public class OkHttp {
} }
public static String string(String url, Map<String, String> params, Map<String, String> header) { public static String string(String url, Map<String, String> params, Map<String, String> header) {
return url.startsWith("http") ? new OkRequest(GET, url, params, header).execute(client()).getBody() : ""; return new OkRequest(GET, url, params, header).execute(client()).getBody();
} }
public static String post(String url, Map<String, String> params) { public static String post(String url, Map<String, String> params) {

View File

@ -2,6 +2,7 @@ package com.github.catvod.net;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.utils.Util; import com.github.catvod.utils.Util;
import java.io.IOException; import java.io.IOException;
@ -37,10 +38,10 @@ class OkRequest {
this.method = method; this.method = method;
this.params = params; this.params = params;
this.header = header; this.header = header;
getInstance(); this.buildRequest();
} }
private void getInstance() { private void buildRequest() {
Request.Builder builder = new Request.Builder(); Request.Builder builder = new Request.Builder();
if (method.equals(OkHttp.GET) && params != null) setParams(); if (method.equals(OkHttp.GET) && params != null) setParams();
if (method.equals(OkHttp.POST)) builder.post(getRequestBody()); if (method.equals(OkHttp.POST)) builder.post(getRequestBody());
@ -62,10 +63,10 @@ class OkRequest {
} }
public OkResult execute(OkHttpClient client) { public OkResult execute(OkHttpClient client) {
try { try (Response res = client.newCall(request).execute()) {
Response response = client.newCall(request).execute(); return new OkResult(res.code(), res.body().string(), res.headers().toMultimap());
return new OkResult(response.code(), response.body().string(), response.headers().toMultimap());
} catch (IOException e) { } catch (IOException e) {
SpiderDebug.log(e);
return new OkResult(); return new OkResult();
} }
} }

View File

@ -71,6 +71,7 @@ public class Market extends Spider {
if (file.getName().endsWith(".apk")) FileUtil.openFile(file); if (file.getName().endsWith(".apk")) FileUtil.openFile(file);
else Result.notify("下載完成"); else Result.notify("下載完成");
checkCopy(action); checkCopy(action);
response.close();
dismiss(); dismiss();
return ""; return "";
} catch (Exception e) { } catch (Exception e) {