我希望在一次调用中为我的REST服务发送两种类型的内容;是否可以将多部分/混合消息作为纯文本发送?
我在我的代码中使用以下内容;
部首: 内容类型:多部分/混合; boundary =“简单边界”
--simple boundary
Content-type: text/plain;name="file-data"
This is implicitly typed plain ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; name="file"
This is explicitly typed plain ASCII text.
It DOES end with a linebreak.
--simple boundary--
This is the epilogue. It is also to be ignored.
我已经通过POSTman发送了这个。它将击中我的弹簧控制器:
@RequestMapping(method = { RequestMethod.POST }, value = "/multipart",
consumes = { "multipart/mixed" })
@ResponseStatus(HttpStatus.OK)
public void multipartSplitter(@RequestPart("file-data") String file){
LOGGER.info("This is the file: " +file);
我有以下bean设置;
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
并使用:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
我目前正在; “HTTP状态400 - 所需的请求部分'文件数据'不存在。”和“客户发送的请求在语法上是不正确的。”
请告知