项目中通过post请求返回的数据为空的。原因是数据格式为xml数据,百度搜索发现也有人碰到过相似事情,记录下这位小伙伴的
增加配置:
// 覆盖egg自带的配置 使支持接收xml参数
config.bodyParser = {
enable: true,
encoding: 'utf8',
formLimit: '100kb',
jsonLimit: '100kb',
strict: true,
// @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
queryString: {
arrayLimit: 100,
depth: 5,
parameterLimit: 1000,
},
enableTypes: ['json', 'form', 'text'],
extendTypes: {
text: ['text/xml', 'application/xml'],
},
};
然后就可以正常获取到xml数据了
改了以后,post提交的xml数据,通过ctx.request.body就能拿到
原作者:https://blog.csdn.net/foreverling_ling/article/details/93726083
网友评论