所有人!
我正在尝试向Rest Service发送请求以上传PDF文件,但HTTP状态为400。
该服务允许发送多个文件,但仅需要一个。 WADL定义为:
0.0176
就我而言,我只想在“ attatchment1”中发送一个文件。我正在使用jersey-multipart,并且我有这种方法来创建multipart对象:
<resource path="/uploadFiles">
<method name="POST" id="uploadDocuments">
<request>
<representation mediaType="multipart/mixed">
<param name="attachment1" style="query" type="xs:anyType"/>
<param name="attachment2" style="query" type="xs:anyType"/>
<param name="attachment3" style="query" type="xs:anyType"/>
</representation>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
}
这是我必须发送请求的客户端:
private MultiPart createMultiPart (String fileName){
File file = new File(fileName);
final FileDataBodyPart bodyPart = new FileDataBodyPart(fileName, file);
final FormDataContentDisposition dispo = FormDataContentDisposition
.name("attachment1")
.fileName(fileName)
.size(file.length())
.build();
bodyPart.contentDisposition(dispo);
final MultiPart multBody = new MultiPart().bodyPart(fd);
return multBody;
我认为麻烦是我在创建multiPart对象时遇到任何错误。有谁知道霍伊解决方案?
谢谢!