如何使用postman传数组数据
时间:2019-03-27 22:05:18
收藏:0
阅读:3661
如何使用postman传数组数据
在我们做api接口数据调试的时候,大部分是会用到postman的,一般请求数据的参数都是字符串,但是特殊情况下我们是需要传一个数组数据的,那么为了实现这种需求,究竟该怎么做呢?请看下文
看了网上的很多文档,试了一个网页的链接,没有一个实现我的需求,主要是解释文档重点模糊,导致读者不明所以,所以我又单独写这个文档出来释疑。请看重点
method
POST
params
name:测试鞋子
desc:测试描述
imgs:【1,2】
具体实现
首先是params照常填写正常的参数即可
其次是headers需要进行设置Content-Type
最后在body中选择raw、以及json(application/json)
postman本地返回结果
服务器接收数据结果
服务器端代码,无需关注,除非自己本地使用nodejs连接了mongodb数据库,只是给真的用了mongodb数据库的看一下逻辑

const { ProductType } = require(‘../../../modules‘); const express = require(‘express‘); const router = express.Router(); router.post(‘/imgs‘, async (req, res) => { const pt = ProductType(); pt.name = req.query.name; pt.description = req.query.desc; pt.imgs = req.body.imgs; const result = await pt.save(); res.json({ status: ‘success‘, info: result }) }) module.exports = router;
希望能够帮到大家!
有用点个赞再走呗0,0
原文:https://www.cnblogs.com/gitByLegend/p/10611192.html
评论(0)