我正在创建一个安静的 Web 服务来处理来自用户的多个文件。从谷歌看来,正确的 mime 类型应该是多部分/混合的,所以我的 java web 服务代码(基于 Jersey)类似于:
@POST
@Consumes(MultiPartMediaTypes.MULTIPART_MIXED)
@Produces({
MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON
})
@Path("/{Id}")
public CourseBean updateCourse(@PathParam("Id") final String id, final MultiPart multipart)
throws WebServiceException
{
//operations on multipart
String this.id = id;
return null;
}
在浏览器中,我运行下面的 html 以尝试将文件上传到 Web 服务:
<h1></h1>
<p>files</p>
<FORM action="http://localhost:8080/rest/1"
enctype="multipart/mixed"
method="POST">
<p>
name:<INPUT type="text" name="submit-name"><BR>
file <INPUT type="file" name="file"><BR>
attachment <INPUT type="file" name="attachment"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</FORM>
</body>
</html>
请注意这里的 enctype 是“ multipart/mixed ”。但是,在我选择文件并单击发送按钮后,我的 Web 服务获取的 http 请求的 mime 类型更改为application/x-www-form-urlencoded,这会导致 Web 服务端出现“不支持的媒体类型”错误.
但是如果我将 html 中的 enctype 更改为multipart/form-data,则接收到的请求的 mime 类型是相同的:multipart/form-data。
所以我的问题是,我怎样才能创建一个 html 表单,它可以发送带有 mime 类型“multipart/mixed”的 http 消息?使用这个 html,我可以测试我的网络服务。
非常感谢你。