if(contentEncoding != null && contentEncoding.length() == 0) {
contentEncoding = null;
}
// Write the request to our own stream
MultipartEntity multiPart = new MultipartEntity(
getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT);
// Create the parts
// Add any parameters
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
String parameterName = arg.getName();
if (arg.isSkippable(parameterName)){
continue;
}
FormBodyPart formPart;
StringBody stringBody = new StringBody(arg.getValue(),
Charset.forName(contentEncoding == null ? "US-ASCII" : contentEncoding));
formPart = new FormBodyPart(arg.getName(), stringBody);
multiPart.addPart(formPart);
}
// Add any files
// Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
for (int i=0; i < files.length; i++) {
HTTPFileArg file = files[i];
fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
multiPart.addPart(file.getParamName(),fileBodies[i]);
}
post.setEntity(multiPart);
if (multiPart.isRepeatable()){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for(ViewableFileBody fileBody : fileBodies){
fileBody.hideFileData = true;
}
multiPart.writeTo(bos);
for(ViewableFileBody fileBody : fileBodies){
fileBody.hideFileData = false;
}
bos.flush();
// We get the posted bytes using the encoding used to create it