return request;
}
private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
HttpPost request = new HttpPost(uri);
MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
try {
Charset utf8 = Charset.forName("UTF-8");
for(Parameter param : parameters)
if(param.isSingleValue())
multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
else
for(String value : param.getValues())
multiPartEntity.addPart(param.getName(), new StringBody(value, utf8));
} catch (UnsupportedEncodingException e) {
throw MechanizeExceptionFactory.newException(e);
}
List<String> fileNames = new ArrayList<String>(files.keySet());
Collections.sort(fileNames);
for(String name : fileNames) {
ContentBody contentBody = files.get(name);
multiPartEntity.addPart(name, contentBody);
}
request.setEntity(multiPartEntity);
return request;
}