Clean
This commit is contained in:
parent
5f31a3d442
commit
71ae952b74
|
|
@ -37,18 +37,10 @@ public class OkHttp {
|
|||
return Loader.INSTANCE;
|
||||
}
|
||||
|
||||
public static Response newCall(Request request) throws IOException {
|
||||
return client().newCall(request).execute();
|
||||
}
|
||||
|
||||
public static Response newCall(String url) throws IOException {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.github.catvod.net;
|
|||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.utils.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -37,10 +38,10 @@ class OkRequest {
|
|||
this.method = method;
|
||||
this.params = params;
|
||||
this.header = header;
|
||||
getInstance();
|
||||
this.buildRequest();
|
||||
}
|
||||
|
||||
private void getInstance() {
|
||||
private void buildRequest() {
|
||||
Request.Builder builder = new Request.Builder();
|
||||
if (method.equals(OkHttp.GET) && params != null) setParams();
|
||||
if (method.equals(OkHttp.POST)) builder.post(getRequestBody());
|
||||
|
|
@ -62,10 +63,10 @@ class OkRequest {
|
|||
}
|
||||
|
||||
public OkResult execute(OkHttpClient client) {
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
return new OkResult(response.code(), response.body().string(), response.headers().toMultimap());
|
||||
try (Response res = client.newCall(request).execute()) {
|
||||
return new OkResult(res.code(), res.body().string(), res.headers().toMultimap());
|
||||
} catch (IOException e) {
|
||||
SpiderDebug.log(e);
|
||||
return new OkResult();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class Market extends Spider {
|
|||
if (file.getName().endsWith(".apk")) FileUtil.openFile(file);
|
||||
else Result.notify("下載完成");
|
||||
checkCopy(action);
|
||||
response.close();
|
||||
dismiss();
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue