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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:25:31  来源:igfitidea点击:

POSTMAN for Multipart/form-data

springweb-servicesrestmultipartform-datapostman

提问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

enter image description here

在此处输入图片说明

Steps to use 'Multipart/form-data 'in Postman

在 Postman 中使用“Multipart/form-data”的步骤

  1. Create a new tab
  2. Insert controller Url
  3. Set method type as POST
  4. Under Bodytab, select form-data
  5. For each key that is a file, set Valuetype as File
  1. 创建一个新选项卡
  2. 插入控制器 URL
  3. 将方法类型设置为 POST
  4. 正文选项卡下,选择表单数据
  5. 对于作为文件的每个键,将类型设置为文件

回答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 请求中上传多个文件类型/内容类型的特定场景,有一种解决方法。

  1. Set the Header Content-Typeto multipart/mixed.
  2. Select the form-dataoption in Body.
  3. Convert all of your items into files. String content should become a text file, etc.
  4. Add each file by selecting file, adding a key name.
  1. 将标题设置Content-Typemultipart/mixed.
  2. 选择中的form-data选项Body
  3. 将您的所有项目转换为文件。字符串内容应该变成文本文件等。
  4. 通过选择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-TypeContent-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 的文本文件。