简体   繁体   English

Postman - 如何发布多个条目

[英]Postman - how to post multiple entries

I am trying to add multiple entries into my database by using Postman.我正在尝试使用 Postman 将多个条目添加到我的数据库中。

My POST-method is made for single entries.我的 POST 方法适用于单个条目。 Is there a way to do this without writing an extra method for the bulk import?有没有办法在不为批量导入编写额外方法的情况下做到这一点?

My bulk data looks like:我的批量数据如下所示:

[
    { "Lastname": "Test", "Firstname": "Test", "Department": "IT", "Location": "", "Company": "Test"},
    { "Lastname": "Test2", "Firstname": "Test", "Department": "DEV", "Location": "", "Company": "Test"},
    { "Lastname": "Test3", "Firstname": "Test", "Department": "SD", "Location": "", "Company": "Test"}
]

My POST-API looks like this:我的 POST-API 如下所示:

[HttpPost]
public async Task<IActionResult> Post([FromBody] Person person)
{
   ...
}

If your method is made for ONE entry, then the method can only accept one.如果您的方法是为 ONE 条目制作的,那么该方法只能接受一个。 You should create a new method that accepts a List of entries or an even easier option would be if you just insert all the data directly in the database and so no extra method is needed.您应该创建一个接受条目列表的新方法,或者如果您只是将所有数据直接插入数据库中,则更简单的选择是不需要额外的方法。

If the data you have is either in CSV or JSON format then you could use Postman Runner to send multiple requests one after the other to add the data into your database.如果您拥有的数据是CSVJSON格式,那么您可以使用Postman Runner一个接一个地发送多个请求以将数据添加到您的数据库中。 You can also adjust the time between calls to not load your server with too many requests.您还可以调整调用之间的时间,以免服务器加载过多的请求。

Here is an example on how to use Post Runner to make multiple calls with different params, https://stackoverflow.com/a/59457273/8568784这是一个关于如何使用Post Runner使用不同参数进行多次调用的示例, https://stackoverflow.com/a/59457273/8568784

You will have to create a new POST method that accepts a collection of Person objects.您将必须创建一个接受Person对象集合的新POST方法。 Please refer to the code snippet below.请参考下面的代码片段。

[HttpPost]
public async Task<IActionResult> PostAll([FromBody]List<Person> people)
{
    ...
}

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM