From 39fecb09a7796b8742a91036ec3df35c9ff62dbb Mon Sep 17 00:00:00 2001 From: huangzhuanghua <401742778@qq.com> Date: Mon, 1 Aug 2016 10:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E4=BB=A3=E7=A0=81=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?.gitignore=E6=96=87=E4=BB=B6=EF=BC=88=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BF=BD=E7=95=A5misc.xml=E6=96=87=E4=BB=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../java/com/gh/download/DownloadThread.java | 43 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 1d019726cd..529e325cff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /.idea +.idea/misc.xml *.iml .gradle /local.properties .DS_Store /build -/captures +/captures \ No newline at end of file diff --git a/app/src/main/java/com/gh/download/DownloadThread.java b/app/src/main/java/com/gh/download/DownloadThread.java index 6bf7d595a7..e20709cc8f 100644 --- a/app/src/main/java/com/gh/download/DownloadThread.java +++ b/app/src/main/java/com/gh/download/DownloadThread.java @@ -4,7 +4,6 @@ import android.content.Context; import android.text.TextUtils; import android.util.Log; -import com.gh.common.util.HttpdnsUtils; import com.gh.common.util.Trace; import com.gh.common.util.Utils; @@ -25,7 +24,7 @@ public class DownloadThread extends Thread { private DownloadListener listener; private DownloadStatus status; private Context context; - private boolean getNewurlSuccess = false; +// private boolean getNewurlSuccess = false; public DownloadThread(Context context, DownloadEntry entry, DownloadListener listener) { @@ -55,20 +54,20 @@ public class DownloadThread extends Thread { } //Httpdns替换地址 - String newUrl = HttpdnsUtils.getUrls(context, entry.getUrl()); - if (newUrl == null) { - newUrl = entry.getUrl(); - getNewurlSuccess = false; - Utils.log("HttpDnsService::获取新地址失败,用原地址进行下载,原地址为::"+newUrl); - } else { - getNewurlSuccess = true; - Utils.log("HttpDnsService::获取新地址成功,目标地址为::"+newUrl); - } +// String newUrl = HttpdnsUtils.getUrls(context, entry.getUrl()); +// if (newUrl == null) { +// newUrl = entry.getUrl(); +// getNewurlSuccess = false; +// Utils.log("HttpDnsService::获取新地址失败,用原地址进行下载,原地址为::"+newUrl); +// } else { +// getNewurlSuccess = true; +// Utils.log("HttpDnsService::获取新地址成功,目标地址为::"+newUrl); +// } URL url = new URL(entry.getUrl()); -// HttpURLConnection connection = (HttpURLConnection) url -// .openConnection(); - HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection(); + HttpURLConnection connection = (HttpURLConnection) url + .openConnection(); +// HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(CONNECT_TIME); connection.setReadTimeout(READ_TIME); @@ -76,10 +75,10 @@ public class DownloadThread extends Thread { "bytes=" + targetFile.length() + "-"); //获取新地址成功,设置HTTP请求头Host域 - if (getNewurlSuccess &&newUrl.endsWith(".apk") ){ - //非.apk,结尾的下载地址不需要加请求头Host域 - connection.setRequestProperty("Host", url.getHost()); - } +// if (getNewurlSuccess && newUrl.endsWith(".apk") ){ +// //非.apk,结尾的下载地址不需要加请求头Host域 +// connection.setRequestProperty("Host", url.getHost()); +// } //设置自动重定向 connection.setInstanceFollowRedirects(true); @@ -100,10 +99,10 @@ public class DownloadThread extends Thread { connection.setReadTimeout(READ_TIME); connection.setRequestProperty("RANGE", "bytes=" + targetFile.length() + "-"); - if (getNewurlSuccess &&newUrl.endsWith(".apk") ){ - //非.apk,结尾的下载地址不需要加请求头Host域 - connection.setRequestProperty("Host", url.getHost()); - } +// if (getNewurlSuccess && newUrl.endsWith(".apk") ){ +// //非.apk,结尾的下载地址不需要加请求头Host域 +// connection.setRequestProperty("Host", url.getHost()); +// } //设置自动重定向 connection.setInstanceFollowRedirects(true); }