|
@@ -74,11 +74,11 @@ public class APIUtil {
|
74
|
74
|
}
|
75
|
75
|
|
76
|
76
|
public static Headers buildHeaders(Map<String, String> headers) {
|
77
|
|
- if (null == headers) return null;
|
78
|
|
-
|
79
|
77
|
Headers.Builder builder = new Headers.Builder();
|
80
|
|
- for (Map.Entry<String, String> entry: headers.entrySet()) {
|
81
|
|
- builder.add(entry.getKey(), entry.getValue());
|
|
78
|
+ if (null != headers) {
|
|
79
|
+ for (Map.Entry<String, String> entry: headers.entrySet()) {
|
|
80
|
+ builder.add(entry.getKey(), entry.getValue());
|
|
81
|
+ }
|
82
|
82
|
}
|
83
|
83
|
return builder.build();
|
84
|
84
|
}
|
|
@@ -119,7 +119,9 @@ public class APIUtil {
|
119
|
119
|
} else if (fieldValue instanceof FileInputStream) {
|
120
|
120
|
buildFileInputStream(builder, (FileInputStream) fieldValue, fieldName);
|
121
|
121
|
} else if (fieldValue instanceof ByteBuffer) {
|
122
|
|
- buildFileBytes(builder, ((ByteBuffer) fieldValue).array(), fieldName);
|
|
122
|
+ byte[] array = new byte[((ByteBuffer) fieldValue).remaining()];
|
|
123
|
+ ((ByteBuffer) fieldValue).get(array);
|
|
124
|
+ buildFileBytes(builder, array, fieldName);
|
123
|
125
|
} else if (fieldValue instanceof Array) {
|
124
|
126
|
for (int i = 0; i < Array.getLength(fieldValue); i ++) {
|
125
|
127
|
Object item = Array.get(fieldValue, i);
|
|
@@ -161,7 +163,7 @@ public class APIUtil {
|
161
|
163
|
|
162
|
164
|
MediaType tp = MediaType.get("application/octet-stream");
|
163
|
165
|
RequestBody body = RequestBody.create(tp, content);
|
164
|
|
- builder.addFormDataPart(field, "未知文件", body);
|
|
166
|
+ builder.addFormDataPart(field, "未知文件.jpg", body);
|
165
|
167
|
} catch (IOException e) {
|
166
|
168
|
e.printStackTrace();
|
167
|
169
|
log.error("转换 form-data 数据 到 body 失败: " + e.getMessage());
|
|
@@ -171,7 +173,7 @@ public class APIUtil {
|
171
|
173
|
private static void buildFileBytes(MultipartBody.Builder builder, byte[] content, String field) {
|
172
|
174
|
MediaType tp = MediaType.get("application/octet-stream");
|
173
|
175
|
RequestBody body = RequestBody.create(tp, content);
|
174
|
|
- builder.addFormDataPart(field, "未知文件", body);
|
|
176
|
+ builder.addFormDataPart(field, "未知文件.jpg", body);
|
175
|
177
|
}
|
176
|
178
|
|
177
|
179
|
private static String getSearchString(Map<String, String> query) {
|