下载支持代理
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");
|
String ret = HttpTools.get("https://api.lolicon.app/setu/v2?r18=2");
|
||||||
JSONObject json = JSONObject.parseObject(ret);
|
JSONObject json = JSONObject.parseObject(ret);
|
||||||
HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"),
|
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
|
@Override
|
||||||
public void onDownload(File file) {
|
public void onDownload(File file) {
|
||||||
super.onDownload(file);
|
super.onDownload(file);
|
||||||
|
@ -164,21 +164,36 @@ public class HttpTools {
|
|||||||
private static String donwloadPath = "tmp" + File.separator;
|
private static String donwloadPath = "tmp" + File.separator;
|
||||||
|
|
||||||
public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) {
|
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() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
File jar = null;
|
File jar = null;
|
||||||
try {
|
try {
|
||||||
File savePath = new File(donwloadPath);
|
File savePath = new File(donwloadPath);
|
||||||
|
Proxy proxy=null;
|
||||||
if (!savePath.exists()) {
|
if (!savePath.exists()) {
|
||||||
savePath.mkdirs();
|
savePath.mkdirs();
|
||||||
}
|
}
|
||||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||||
|
if (isProxy){
|
||||||
|
proxy=new Proxy(Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1",7890));
|
||||||
|
}
|
||||||
URLConnection connection;
|
URLConnection connection;
|
||||||
if(url.startsWith("https:")) {
|
if(url.startsWith("https:")) {
|
||||||
connection = (HttpsURLConnection) new URL(url).openConnection();
|
if(isProxy) {
|
||||||
|
connection = (HttpsURLConnection) new URL(url).openConnection(proxy);
|
||||||
|
}else{
|
||||||
|
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
connection=(HttpURLConnection)new URL(url).openConnection();
|
if(isProxy) {
|
||||||
|
connection = (HttpURLConnection) new URL(url).openConnection(proxy);
|
||||||
|
}else{
|
||||||
|
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.addRequestProperty("User-Agent", getExtUa());
|
connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
|
Loading…
Reference in New Issue
Block a user