完整方法代码。
public static String sendPost(String url, JSONObject jsonObject, String token,File file) {
StringBuilder urlBuilder = new StringBuilder(baseURLPath);
urlBuilder.append(url);
log.info(“URL:” + url);
log.info(“Parm:” + jsonObject);
FileBody fileBody=new FileBody(file);
MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
try {
reqEntity.addBinaryBody(“file”, new FileInputStream(file), ContentType.DEFAULT_BINARY, file.getName());
Iterator iter = jsonObject.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
System.out.println(entry.getKey().toString());
System.out.println(entry.getValue().toString());
StringBody value = new StringBody(entry.getValue().toString(), ContentType.create(“text/plain”, Consts.UTF_8));
reqEntity.addPart(entry.getKey().