下载支持代理
This commit is contained in:
parent
2da36d7918
commit
f6c9748f48
@ -33,7 +33,9 @@ public class GetSeTu extends Model {
|
||||
String ret = HttpTools.get("https://api.lolicon.app/setu/v2?r18=2");
|
||||
JSONObject json = JSONObject.parseObject(ret);
|
||||
HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"),
|
||||
System.currentTimeMillis()+"_setu.jpg", new DownloadInterface() {
|
||||
System.currentTimeMillis()+"_setu.jpg",
|
||||
true
|
||||
, new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
|
@ -164,22 +164,37 @@ public class HttpTools {
|
||||
private static String donwloadPath = "tmp" + File.separator;
|
||||
|
||||
public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) {
|
||||
download(url,saveName,false,downloadInterface);
|
||||
}
|
||||
public synchronized static void download(final String url, final String saveName,boolean isProxy, final DownloadInterface downloadInterface) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File jar = null;
|
||||
try {
|
||||
File savePath = new File(donwloadPath);
|
||||
Proxy proxy=null;
|
||||
if (!savePath.exists()) {
|
||||
savePath.mkdirs();
|
||||
}
|
||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||
if (isProxy){
|
||||
proxy=new Proxy(Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1",7890));
|
||||
}
|
||||
URLConnection connection;
|
||||
if(url.startsWith("https:")) {
|
||||
if(isProxy) {
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection(proxy);
|
||||
}else{
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
}else{
|
||||
if(isProxy) {
|
||||
connection = (HttpURLConnection) new URL(url).openConnection(proxy);
|
||||
}else{
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
}
|
||||
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||
|
Loading…
Reference in New Issue
Block a user