javascript - Please answer, the parameter obtained by koa-bodyparser is an empty object, why? ? ? ? ?
欧阳克
欧阳克 2017-07-05 10:40:07
0
2
723

code show as below

const Koa = require('koa'); const app = new Koa(); const router = require('koa-router')(); const bodyParser = require('koa-bodyparser'); app.use(bodyParser()); router.post('/test', async function (ctx, next) { ctx.body = ctx.request; console.log(`我是router中的=====> ${JSON.stringify(ctx.request.body)}`); // 这里得到是一个空对象 }); app.use(router.routes()); app.listen(3000)

Then I requested this interface and what was returned to me was an empty object. Please give me an answer {}

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all (2)
阿神

1. Pay attention to the content-type sent by postman each time. Application/x-www-form-urlencoded or application/json

2. If it is json, the json written using raw must be in a standard format, with double quotes for the key and double quotes for the value string.

    phpcn_u1582

    Tryctx.request.fields

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!