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 {}
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.
Try
ctx.request.fields