Commit f11bb30d08425821cd65cc4ae56acf5ee28c0a5b

Authored by gaoming
1 parent 57b3d3a3
Exists in master

优化

@@ -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.8' 57 + version '1.1.9'
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
@@ -185,6 +185,29 @@ public class UtilHttpByOkHttp { @@ -185,6 +185,29 @@ public class UtilHttpByOkHttp {
185 } 185 }
186 186
187 187
  188 +
  189 + public static ResponseBody sendPostFile(String url, File file,String fileKey,Map<String, String> header) throws Exception {
  190 + OkHttpClient client = new OkHttpClient();
  191 + RequestBody requestBody = new MultipartBody.Builder()
  192 + .setType(MultipartBody.FORM)
  193 + .addFormDataPart(fileKey, file.getName(),
  194 + RequestBody.create(MediaType.parse("multipart/form-data"), file))
  195 + .build();
  196 +
  197 + Request request = new Request.Builder()
  198 + .headers(Headers.of(header))
  199 + .url(url)
  200 + .post(requestBody)
  201 + .build();
  202 +
  203 + Response response = client.newCall(request).execute();
  204 + if (!response.isSuccessful()){
  205 + throw new IOException("Unexpected code " + response);
  206 + }
  207 + return response.body();
  208 + }
  209 +
  210 +
188 static TrustManager[] trustAllCerts = new TrustManager[]{ 211 static TrustManager[] trustAllCerts = new TrustManager[]{
189 new X509TrustManager() { 212 new X509TrustManager() {
190 public java.security.cert.X509Certificate[] getAcceptedIssuers() { 213 public java.security.cert.X509Certificate[] getAcceptedIssuers() {