下载支持代理
This commit is contained in:
@@ -164,21 +164,36 @@ 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:")) {
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
if(isProxy) {
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection(proxy);
|
||||
}else{
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
}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());
|
||||
|
||||
Reference in New Issue
Block a user