refactor the post multipartfile

This commit is contained in:
fanfuxiaoran 2014-05-04 17:25:22 +08:00
parent 9fc26763bd
commit 24ffcd6925
2 changed files with 58 additions and 51 deletions

View File

@ -134,7 +134,9 @@ public class HttpRequester {
} }
Part[] parts = new Part[files.size() + strings.size()]; Part[] parts = new Part[files.size() + strings.size()];
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
parts[i] = new FilePart(filePartName, files.get(i)); FilePart filePart = new FilePart(filePartName, files.get(i)
.getName(), files.get(i));
parts[i] = filePart;
} }
for (int i = 0; i < strings.size(); i++) { for (int i = 0; i < strings.size(); i++) {
parts[i + files.size()] = new StringPart(stringPartName, parts[i + files.size()] = new StringPart(stringPartName,
@ -157,14 +159,16 @@ public class HttpRequester {
List<File> files = new LinkedList<File>(); List<File> files = new LinkedList<File>();
if (multipartFiles != null) { if (multipartFiles != null) {
for (MultipartFile multipartFile : multipartFiles) { for (MultipartFile multipartFile : multipartFiles) {
File file = new File("paramFile.txt"); File file = new File(multipartFile.getOriginalFilename());
multipartFile.transferTo(file); multipartFile.transferTo(file);
files.add(file); files.add(file);
} }
} }
return postFiles(headers, url, filePartName, files, stringPartName, return postFiles(headers, url, filePartName, files, stringPartName,
strings); strings);
} }
private HttpResponse send(String urlString, String method, private HttpResponse send(String urlString, String method,

View File

@ -10,6 +10,9 @@ public class UserModel {
private String password; private String password;
private byte scope; private byte scope;
public UserModel(){
}
@XmlElement @XmlElement
public int getId() { public int getId() {
return id; return id;