441620
报错信息如下
用浏览器访问接口,得到的数据如下:
贴上代码:
var https = require('https') // Node.js提供了http模块,用于搭建HTTP服务端和客户端
function sendRequest(path) {
return new Promise(function (resolve, reject) {
https.get({
path: path,
hostname: 'cnodejs.org',
headers: {
Accept: 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
}
}, function (res) { //发送get请求
var result = null
res.on('data', function (data) {
result = '' + data
})
res.on('end', function () {
resolve(JSON.parse(result, (key, value) => {
if (['content', 'title'].indexOf(key) > -1) {
return ''
} else {
return value
}
}))
})
}).on('error', function (e) {
reject(e)
})
})
}
sendRequest('/api/v1/topics').then(res => {
console.log(res.data.length)
}).catch(e => {
console.log(e)
})
请问有没有什么办法可以解决这个问题?