Commit 5b4a61ad3035ce784c9926c7ca3d5195871439ab
1 parent
09729c59
Exists in
master
1.增加okhttp download file方法
Showing
2 changed files
with
7 additions
and
1 deletions
Show diff stats
build.gradle
| @@ -54,7 +54,7 @@ uploadArchives { | @@ -54,7 +54,7 @@ uploadArchives { | ||
| 54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
| 55 | } | 55 | } |
| 56 | pom.project { | 56 | pom.project { |
| 57 | - version '1.1.2' | 57 | + version '1.1.3' |
| 58 | artifactId ARTIFACT_Id | 58 | artifactId ARTIFACT_Id |
| 59 | groupId GROUP_ID | 59 | groupId GROUP_ID |
| 60 | packaging TYPE | 60 | packaging TYPE |
src/main/java/com/taover/util/UtilHttpByOkHttp.java
| @@ -73,6 +73,12 @@ public class UtilHttpByOkHttp { | @@ -73,6 +73,12 @@ public class UtilHttpByOkHttp { | ||
| 73 | return getHttpClient(url).newCall(request).execute().body().string(); | 73 | return getHttpClient(url).newCall(request).execute().body().string(); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | + public static byte[] downloadFile(String url, final Map<String, String> headers) throws Exception{ | ||
| 77 | + Request request = getRequestBuilder(url, headers).get().build(); | ||
| 78 | + | ||
| 79 | + return getHttpClient(url).newCall(request).execute().body().bytes(); | ||
| 80 | + } | ||
| 81 | + | ||
| 76 | private static OkHttpClient getHttpClient(String url){ | 82 | private static OkHttpClient getHttpClient(String url){ |
| 77 | if(url.trim().toLowerCase().startsWith("https")){ | 83 | if(url.trim().toLowerCase().startsWith("https")){ |
| 78 | return buildOkHttpClientForHttps(); | 84 | return buildOkHttpClientForHttps(); |