在使用application/x-www-urlencoded方式请求时,当传入的参数为数组集合类型时,会被body-parser错误解析需要通过设置urlencoded > extended为false
参考资料
- https://stackoverflow.com/questions/55558402/what-is-the-meaning-of-bodyparser-urlencoded-extended-true-and-bodypar
- https://forum.freecodecamp.org/t/post-request-empty-body-parser-extended-true-still-not-working/451962
- https://www.tabnine.com/code/javascript/functions/body-parser/urlencoded
sh
# 正确发送的FormData格式
list[0].xxx=1
list[1].xxx=2
# urlencoded后
list[0].xxx=1&list[1].xxx=2
错误解析

js
// 传入的数据格式
const list = [{ aaa: 1, bbb: 2 }];
request({ list }).then(res => {
// ...
})
nodejs中间件配置:
js
const app = express();
const bodyParser = require('body-parser');
// 必须放置其他bodayParser之前否则无效
app.use(bodyParser.urlencoded({ extend: false }));
app.use(bodyParser.json());
app.use(xxx);
正确解析
