|
@@ -1,6 +1,5 @@
|
|
|
package cn.com.qmth.examcloud.commons.util;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -9,6 +8,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.FormFileDataPart;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
import okhttp3.FormBody;
|
|
@@ -248,42 +248,6 @@ public class OKHttpUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 表单文件参数
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2019年4月10日
|
|
|
- * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
|
|
|
- */
|
|
|
- public static class FileDataPart {
|
|
|
-
|
|
|
- private String name;
|
|
|
-
|
|
|
- private String filename;
|
|
|
-
|
|
|
- private File file;
|
|
|
-
|
|
|
- public FileDataPart(String name, String filename, File file) {
|
|
|
- super();
|
|
|
- this.name = name;
|
|
|
- this.filename = filename;
|
|
|
- this.file = file;
|
|
|
- }
|
|
|
-
|
|
|
- public String getName() {
|
|
|
- return name;
|
|
|
- }
|
|
|
-
|
|
|
- public String getFilename() {
|
|
|
- return filename;
|
|
|
- }
|
|
|
-
|
|
|
- public File getFile() {
|
|
|
- return file;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 发送请求 (包含文件表单)
|
|
|
*
|
|
@@ -296,7 +260,7 @@ public class OKHttpUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
|
|
|
- Map<String, String> params, List<FileDataPart> fileDataPartList) {
|
|
|
+ Map<String, String> params, List<FormFileDataPart> fileDataPartList) {
|
|
|
|
|
|
LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
|
|
|
LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
|
|
@@ -313,9 +277,9 @@ public class OKHttpUtil {
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(fileDataPartList)) {
|
|
|
MediaType type = MediaType.parse("application/octet-stream");
|
|
|
- for (FileDataPart fileDataPart : fileDataPartList) {
|
|
|
+ for (FormFileDataPart fileDataPart : fileDataPartList) {
|
|
|
RequestBody fileBody = RequestBody.create(type, fileDataPart.getFile());
|
|
|
- multipartBodyBuilder.addFormDataPart(fileDataPart.getName(),
|
|
|
+ multipartBodyBuilder.addFormDataPart(fileDataPart.getParamName(),
|
|
|
fileDataPart.getFilename(), fileBody);
|
|
|
}
|
|
|
}
|