json 如何使用邮递员测试表单数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23780219/
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-03 17:19:25  来源:igfitidea点击:

How to use postman to test formdata?

jsonformspostman

提问by rkshakya99

How can I use postman plugin of Google Chrome to send a FormData() object to a webapi using POST. The FormData() object has form fields personID and messageBody appended to it. I tried something like this but to no avail:

如何使用 Google Chrome 的邮递员插件通过 POST 将 FormData() 对象发送到 webapi。FormData() 对象附加了表单字段 personID 和 messageBody。我试过这样的事情,但无济于事:

URL of the webapi: http://localhost/<<appName>>/api/v1/message

Headers:
Accept:application/json
Content-Type:multipart/form-data; boundary=---XXX---

form-data:
personID:1 (Text)   
messageBody:Hello (Text)

采纳答案by rkshakya99

Yes finally I have made it work. What I was doing wrong was not setting all the fields of the FormData() object ie, I didn't set the fields such as orderId because its value was null. When I set all the field values even if they were null, it worked. And also there was no need to set the Content-Type when you are sending a multipart/form-data...

是的,我终于让它工作了。我做错的是没有设置 FormData() 对象的所有字段,即我没有设置诸如 orderId 之类的字段,因为它的值为空。当我设置所有字段值时,即使它们为空,它也能工作。当您发送多部分/表单数据时,也无需设置 Content-Type ...

回答by Abhinav

Postman has a form-data POST body option that automatically does this for you.

Postman 有一个表单数据 POST 正文选项,可以自动为您执行此操作。