2020-03-03 nodejs解决用got发起http请求中gbk与utf8编码转换问题
废话不多说直接上代码
1 2 3 4 5 6 7 8 9 10 11
| const got = require('got') const iconv = require('iconv-lite') async function getLocation(ip) { const url = 'http://www.ip138.com/iplookup.asp?ip=' + ip + '&action=2' const res = await got.get(url, { encoding: null }) const data = iconv.decode(res.body, 'GBK').match(/本站数据:(.*?)<\/li>/)[1] return data }
|
以上只是举个例子,其他情况类似处理
本文作者:草梅友仁
本文地址: https://blog.cmyr.ltd/archives/81e52f4c.html
版权声明:转载请注明出处!