发送请求时候,
content-type 设置为 text/plain
内容为字符串: xxxxxxxx
在 Controller 接受不了数据,把request打印出来也没有,请问这个如何处理呢?
{
"type": "text/plain",
"body": {
"method": "POST",
"url": "/",
"header": {
"host": "127.0.0.1:7001",
"connection": "keep-alive",
"content-length": "11",
"pragma": "no-cache",
"cache-control": "no-cache",
"accept": "*/*",
"origin": "chrome-extension://lfpkamdkgojifggknghlphggacikkhff",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"sec-fetch-mode": "cors",
"content-type": "text/plain",
"sec-fetch-site": "cross-site",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en,zh-CN;q=0.9,zh;q=0.8,da;q=0.7,zh-TW;q=0.6",
"cookie": "_pk_id.100001.dc78=a2b6ecaa3b706a52.1546333701.1.1546336484.1546333701.; CURRENT_API_ID%23b09de87a3c6dfc02a472de4f87f8f918=%228321067185044f49b031fbe7c4905724%22; Hm_lvt_31325a0b97c093393242fde24a1a4a1d=1569834440; csrfToken=xJ-4L0H1wZH0n_LVRK_M2l37"
}
}
}
自问自答,关闭
const bodyParserConfig: any = {
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'],
},
};
// 覆盖egg自带的配置
config.bodyParser = bodyParserConfig;
config 是会合并的,你不用写那么多。只需要:
config.bodyParser = {
enableTypes: ['json', 'form', 'text'],
extendTypes: {
text: ['text/xml', 'application/xml'],
},
}
Most helpful comment
config 是会合并的,你不用写那么多。只需要: