0

我正在尝试使用新的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();
4

1 回答 1

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();
于 2019-04-11T07:41:04.830 回答