背景:前端用 fetch 发请求,在 node 服务端获取 post 请求数据
方案:前后端均需配置
1、前端 fetch 配置:body 参数需转换为 ‘a=1&b2’ 的形式,可使用 querystring;(2)content-type 需设置为 application/x-www-form-urlencoded
2、node 配置:使用 koa-bodyparser 即可
然后即可从ctx.request.body中取出 body 对象
背景:前端用 fetch 发请求,在 node 服务端获取 post 请求数据
方案:前后端均需配置
1、前端 fetch 配置:body 参数需转换为 ‘a=1&b2’ 的形式,可使用 querystring;(2)content-type 需设置为 application/x-www-form-urlencoded
2、node 配置:使用 koa-bodyparser 即可
然后即可从ctx.request.body中取出 body 对象