const http = require('http');
const fs = require('fs');
let options = {
method: 'GET',
host:"nodejs.cn",
port:80,
path: '/api/',
};
let data = '';
http.get(options, (res) => {
// console.log(res.socket.address(),'\n',res.socket.remoteAddress);
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
fs.writeFileSync('./nodeCn.html',data,()=>{
});
fs.readFile('./nodeCn.html',{encoding :'utf8'},(err,datas)=>{
console.log(datas)
});
console.log('数据包传输完毕');
});
});