スーパーエージェントライブラリのインストールと使用
yarn add superagent
const superagent = require('superagent')
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
'Content-Type': 'text/html;charset=utf-8'
}
try {
superagent('GET', url).set(headers).end((req, res) => {
console.log(res)
}).catch(e=>{
console.log(e)
})
}
catch (e) {
}
中国語の文字化けした文字が応答に表示されます
スーパーエージェント文字セットサポートライブラリをインストールする superagent-charset
yarn add superagent-charset
インポートされたライブラリに依存関係を追加します
const charset = require('superagent-charset');
const superagent = charset(require('superagent'));
superagent('GET', url).charset('gbk').set(headers).end((req, res)
ウェアハウスリンク
npm-superagent-charset