在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ superagent post提交表單數(shù)據(jù)到數(shù)據(jù)庫中文亂碼

superagent post提交表單數(shù)據(jù)到數(shù)據(jù)庫中文亂碼

求助大佬!superagent post提交表單數(shù)據(jù)到數(shù)據(jù)庫中文亂碼,代碼如下:

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': '測(cè)試標(biāo)題,測(cè)試標(biāo)題測(cè)試標(biāo)題測(cè)試標(biāo)題',
    'keyboard': 'aaa,bbb,cccc',
    'smalltext': '測(cè)試描述111的送達(dá)方式方法是',
    'newstext': '內(nèi)容內(nèi)容內(nèi)容'
};
agent
.post('submit.php')
.set(headers)
.set('Content-Type', 'multipart/form-data;')
.type('form')
.send(Object.assign(basicFormData, publishFormData))
.charset('gb2312')
.then(result => {
    console.log(result.text);
})
.catch(err => {
    console.error(err);
})

網(wǎng)站編碼是gb2312,設(shè)置了charset為gb2312,返回result.text的內(nèi)容編碼是正常的,但是模擬提交表單到數(shù)據(jù)庫后就亂碼了,數(shù)據(jù)庫用是mysql,數(shù)據(jù)庫編碼是utf8。

亂碼如下圖所示:

圖片描述

回答
編輯回答
淚染裳

不要被埋啊啊啊~

2017年8月1日 10:31
編輯回答
硬扛

網(wǎng)頁客戶端 和 服務(wù)器端php 需要 相同編碼,推薦 utf-8 ,如果都是 gb2312 ,你 PHP 也需要設(shè)置為 gb2312~

2017年3月22日 21:41