spring 多部分/表单数据的邮递员
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44182746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
POSTMAN for Multipart/form-data
提问by phalco
How to use POSTMAN for Multipart/form-data which has customize header for testing my controller which takes 2 files as parameter (public ... controller( MultipartFile[] files))?
如何将 POSTMAN 用于具有自定义标头的 Multipart/form-data,用于测试以 2 个文件作为参数 ( public ... controller( MultipartFile[] files)) 的控制器?
POST .... HTTP/1.1
.
.
.
---boundary123
Content-type:application/octet-stream
content-Disposition: form-data filenale="abc.txt" name="someuniquename"
[paylaod content](this is in xml format)
---boundary123
content-type:application/json
content-Disposition:form-data name="metadata"
{ID:"999"}
---boundary123
回答by Afridi
回答by Adam Gerard
This is a long-known issue for Postman. It can be a bit tricky if you have a set up that involves using say text or JSON for one part but say a picture for another. The key is to set the Content-TypeHeader to multipart/mixedand then to convert everything into a file. You can ignore the "convert it into a file" step if it's text :)
对于 Postman 来说,这是一个众所周知的问题。如果您的设置涉及对一部分使用文本或 JSON 而对另一部分使用图片,则可能会有点棘手。关键是将Content-TypeHeader设置为multipart/mixed然后将所有内容转换为文件。如果是文本,您可以忽略“将其转换为文件”步骤:)
Left this comment on: https://github.com/postmanlabs/postman-app-support/issues/1104
将此评论留在:https: //github.com/postmanlabs/postman-app-support/issues/1104
Ninja update: Not sure if this will help anyone else but there is a workaround for a specific scenario where you have multiple file types / content types being uploaded in a single multipart POST request.
Ninja 更新:不确定这是否对其他人有帮助,但对于在单个多部分 POST 请求中上传多个文件类型/内容类型的特定场景,有一种解决方法。
- Set the Header
Content-Typetomultipart/mixed. - Select the
form-dataoption inBody. - Convert all of your items into files. String content should become a text file, etc.
- Add each file by selecting
file, adding a key name.
- 将标题设置
Content-Type为multipart/mixed. - 选择中的
form-data选项Body。 - 将您的所有项目转换为文件。字符串内容应该变成文本文件等。
- 通过选择
file,添加密钥名称来添加每个文件。
This approach doesn't require actually manually specifying each Content-Typeor Content-Disposition. The trick here was to serialize all relevant content into a persistent file type. Hope that helps someone!
这种方法不需要实际手动指定每个Content-Type或Content-Disposition. 这里的技巧是将所有相关内容序列化为持久文件类型。希望对某人有所帮助!
回答by Pabitra Dash
This videodescribes how to post multipart/form-data using postman. I uploaded a text file with Content-Type of multipart/form-data.
该视频描述了如何使用邮递员发布多部分/表单数据。我上传了一个内容类型为 multipart/form-data 的文本文件。


