2015-08-03 156 views
0

我们需要使用下面的MultipartFile数组创建一个休息端点。如何向其余端点发送请求包含MultipartFile数组

<!-- language: lang-java --> 
@ResponseStatus(OK) 
@RequestMapping(value = {"/v1/transform"}, method = RequestMethod.POST) 
@ResponseBody 
public TransformIdDTO transformFile(@RequestPart("file") MultipartFile [] multipartFile, @RequestParam("from") String from, @RequestParam("to") String to,final HttpServletResponse response) throws IOException, MessagingException { 
} 

我想用HttpClient和PostMethod编写一个测试用例。如果MultipartFile不是像下面那样的数组,我可以发送一个请求。如果MultipartFile是数组,我无法发送请求。

<!-- language: lang-java --> 
HttpClient client = new HttpClient(); 
PostMethod method1 = new PostMethod("URI"); 
Part[] parts = {new FilePart("file", f),new StringPart("from","html"),new StringPart("to","PDF")}; 
method1.setRequestEntity(new MultipartRequestEntity(parts, method1.getParams())); 
int returnCode = client.executeMethod(method1); 
System.out.println(returnCode); 

请让我知道如何发送请求到包含MultiPartFile数组的端点。

回答

0

我已将@RequestPart的注释更改为@RequestParam,并解决了问题。

相关问题