Superagent library installation and use
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) {
}
Chinese garbled characters appear in the response
Install superagent charset support library superagent-charset
yarn add superagent-charset
Add dependencies in the imported library
const charset = require('superagent-charset');
const superagent = charset(require('superagent'));
superagent('GET', url).charset('gbk').set(headers).end((req, res)
Warehouse link
npm-superagent-charset