我正在尝试使用新的docushare rest api在Docushare Flex中创建新文档,并且我的请求正文应该是XML,并且正在使用请求的数据生成它,当我发送请求时,出现此错误“ org.apache.commons .fileupload.FileUploadException:由于未找到多部分边界,因此请求被拒绝”
HttpPost request = new HttpPost(postUrl);
String filePath = "C:/Test/CreateDocument.xml";
String createObj = helper.createDocumentXml(filePath, parentId, documentTitle, fileName, ownerId);
String createDocumentXml= null;
{
try {
createDocumentXml = FileUtils.readFileToString(new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
}
StringEntity bodyEntity = new StringEntity(createDocumentXml, ContentType.MULTIPART_FORM_DATA);
request.setEntity(bodyEntity);
CloseableHttpResponse response = client.execute(request);
System.out.println("Status is " + response.getStatusLine());
HttpEntity entity = response.getEntity();
答案 0 :(得分:1)
我已使用此代码块在DocuShare Flex中上载文档
HttpPost request = new HttpPost(postUrl);
String filePath = "C:/Test/CreateDocument.xml";
String createObj = helper.createDocumentXml();
String createDocumentXml= null;
{
try {
createDocumentXml = FileUtils.readFileToString(new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
}
FileBody body = new FileBody(file.toFile());
StringBody xmlContent = new StringBody(createDocumentXml, ContentType.APPLICATION_XML);
String boundry = UUID.nameUUIDFromBytes(file.toString().getBytes()).toString();
HttpEntity entity = MultipartEntityBuilder.create()
.setBoundary(boundry)
.setCharset(Charset.forName("UTF-8"))
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)`enter code here`
.addPart("content", body)
.addPart("request", xmlContent)
.build();
request.setEntity(entity);
CloseableHttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();