egg 获取header头为application/json的参数,也就是获取这个地方的值该怎么配置呢
可以在config/config.default.js里面直接开启bodyParser,因为eggjs框架自带了这个库,具体配置如下:
config.bodyParser = { enable: true, encoding: 'utf-8', formLimit: '1mb', jsonLimit: '1mb', // 添加 raw 类型的解析 extendTypes: { text: ['text/plain'], json: ['application/json', 'application/json-patch+json'], text: ['text/xml'], // 添加 raw 类型 raw: ['application/vnd.custom-type'], }, };
然后就可以在ctx.request.body中正常获取了