求助大佬! superagent post 提交表单数据到数据库中文乱码,代码如下:
const headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", "Connection": "keep-alive", "Cache-Control": "no-cache", 'User-Agent': Util.randomUserAgent() };
const basicFormData = { 'id': 0, 'enews': 'AddNews', 'classid': 14, 'bclassid': 10, 'oldchecked': 0, 'ecmsnfrom': 1, 'ecmscheck': 0, 'havetmpic': 0, 'isgood': 0, 'firsttitle': 0, 'dokey': 1, 'copyimg': 1, 'getfirsttitlepic': 1, 'getfirsttitlespicw': 375, 'getfirsttitlespich': 250 }; const publishFormData = { 'title': '测试标题,测试标题测试标题测试标题', 'keyboard': 'aaa,bbb,cccc', 'smalltext': '测试描述 111 的送达方式方法是', 'newstext': '内容内容内容' };
agent .post('submit.php') .set(headers) .set('Content-Type', 'multipart/form-data;') .type('form') .send(Object.assign(basicFormData, publishFormData)) .charset('') .then(result => { console.log(result.text); }) .catch(err => { console.error(err); })
网站编码是 ,设置了 charset 为 ,返回 result.text 的内容编码是正常的,但是模拟提交表单到数据库后就乱码了,数据库用是 mysql,数据库编码是 utf8。
乱码如下图所示: