Java 在Spring中解析多部分/混合
我想在我的Java 在Spring中解析多部分/混合,java,spring,http,spring-mvc,multipart,Java,Spring,Http,Spring Mvc,Multipart,我想在我的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=%&
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&%--
这条消息是一致的,但我无法在Spring中找到解析这条消息的方法
请注意,文件的数量可能会有所不同
我已经尝试过使用commonmultipartresolver
或StandardServletMultipartResolver
,但两者都只支持multipart/formdata
()
在Spring中,除了编写我自己的解析器之外,还有什么方法可以解析这些请求吗?虽然这不是一个很好的解决方案,但它是我发现的唯一一个: 我基本上使用重新实现了
ServletFileUpload
,然后使用commonmultipartresolver的@Path(“api”)将其加载到apache库中
@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();
}
@放
@消耗(“多部分/混合”)
@产生(“多部分/混合”)
公共多部分12(MultiPart MultiPart)引发IOException{
列出bodyParts=multiPart.getBodyParts();
BodyPartEntity bpe=(BodyPartEntity)bodyParts.get(1.getEntity();
}
这是基于泽西岛的spring boot项目