const http = require('http');
const options = { hostname: 'www.example.com', port: 80, path: '/api', method: 'GET' };
const req = http.request(options, (res) => { console.log(`状态码: ${res.statusCode}`); res.on('data', (chunk) => { console.log(`响应主体: ${chunk}`); }); res.on('end', () => { console.log('响应中已无数据。'); }); }); req.on('error', (e) => { console.error(`请求遇到问题: ${e.message}`); }); req.end();
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com