Spring MVC Multipart请求,仅在有效负载和边界中使用xml

时间:2018-02-28 16:04:05

标签: java spring multipartform-data

我试图实现一些东西,即使我知道Spring功能不是严格意义的,我相信它可以做到,但我无法实现。

基本上,拥有以下Spring MVC控制器:

@Controller
@RequestMapping("/mime")
public class MimeController {

    @RequestMapping(value = "/test", method = RequestMethod.POST,
            consumes = {"multipart/*"}, produces = {"text/plain"})
    public String executeSampleService(@RequestParam("json") String json, @RequestParam("xml") String xml ) {
        return "reached";
    }
}

当我尝试从邮递员那里推送以下请求时:

Request Headers:
content-type:"multipart/related; boundary=Ramya"
cache-control:"no-cache"
postman-token:"559ba32f-97f8-423b-b1bb-283ec1d7856c"
user-agent:"PostmanRuntime/7.1.1"
accept:"*/*"
host:"localhost:8080"
accept-encoding:"gzip, deflate"
content-length:269
Request Body:"--Ramya Content-Disposition: form-data; name="json" Content-Type: application/json; charset=UTF-8 {"json":"payload"} --Ramya Content-Disposition: form-data; name="xml" Content-Type: application/xml; charset=ISO-8859-1 <xmlModel><test>blah</test></xmlModel> --Ramya-- "

我似乎无法获得超出以下例外情况的任何内容:

{
    "timestamp": 1519833131951,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.web.multipart.MultipartException",
    "message": "Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: Stream ended unexpectedly",
    "path": "/mime/test"
}

我知道我正在尝试使用用于上传表单和文件的功能,但我可以按照此处的建议在球衣中实现相同功能:

Spring boot multipart/related mime type support

我尝试更改内容类型的标题,尝试将其与multipart / form-data或multipart / mixed相匹配,但我仍然没有运气,任何帮助将不胜感激。

非常感谢!

0 个答案:

没有答案