注意:最后加上end(),否则请求发不出去。切记!!!

    1. const http = require('http');
    2. console.log('http');
    3. http.request({
    4. host: 'localhost',
    5. port: 3000,
    6. path: '/login?name=lisi&pwd=123'
    7. }, (response) => {
    8. //不断更新数据
    9. let body = '';
    10. response.on('data',(data) => {
    11. body += data;
    12. });
    13. response.on('end',() => {
    14. //数据接收完成
    15. console.log(body);
    16. });
    17. }).end();