我想在我的RestController
中像下面这样解析请求
POST http://#.#.#.#:#/report HTTP/1.1
User-Agent: Android
Accept: text/html,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Content-Type: multipart/mixed; boundary=%&REPORT_DIVIDER&%
Authorization: Basic ***
Content-Length: 23236
Host: #.#.#.#:#
Connection: Keep-Alive
Accept-Encoding: gzip
--%&REPORT_DIVIDER&%
Content-Type: application/json
{"content-excluded":true}
--%&REPORT_DIVIDER&%
Content-Disposition: attachment; filename="INSTALLATION"
Content-Type: application/octet-stream
609903cf-fcc0-460c-87db-958e031ac156
--%&REPORT_DIVIDER&%--
此消息符合rfc1341,但我找不到在Spring中解析此消息的方法。
请注意,文件数量可能会有所不同。
我已经尝试过使用CommonsMultipartResolver
或StandardServletMultipartResolver
,但它们都只支持multipart/form-data
(rfc1867)。
除了编写我自己的解析器之外,还有什么方法可以在Spring中解析这些请求呢?
发布于 2018-01-24 10:36:29
虽然这不是一个很好的解决方案,但它是我发现的唯一一个:
实际上,我用this class重新实现了ServletFileUpload
,然后用CommonsMultipartResolver
的this simple subclass将它加载到apache库中。
发布于 2019-11-25 20:30:17
@Path("api")
@PUT
@Consumes("multipart/mixed")
@Produces("multipart/mixed")
public MultiPart twelve( MultiPart multiPart) throws IOException {
List<BodyPart> bodyParts = multiPart.getBodyParts();
BodyPartEntity bpe = (BodyPartEntity) bodyParts.get(1).getEntity();
}
这是为基于泽西的春季启动项目。
https://stackoverflow.com/questions/44036769
复制相似问题