源码:
const http = require('https')
const fs = require('fs')
let url = 'https://www.qq.com/'
http.get(url,(res) =>{
//只要接收就会触发chunk
let rawData = ''
res.on('data',(chunk)=>{
rawData += chunk.toString('utf8')
console.log(chunk.toString('utf8'))
})
res.on('end',()=>{
console.log('数据传输完毕')
fs.writeFileSync('./bibi.html',rawData)
})
}).on('error',(err)=>{
console.log('请求错误')
})
网友评论