var http = require('http');
//1、正常逻辑第一步正常请求,动作进行一次的方法;
function seqRequest(i,limit){
    var req = http.get({host:'www.baidu.com', port:80, path:'/',agent:false},function(res) {
        resultdata = '';
        res.on('data',function(chunk) {
            resultdata += chunk;
        });

        res.on('end',function() {
            console.log(i)
            console.log('return ' + resultdata.length);
            //2、加入循环条件
            if(i<limit){
                //3、继续执行里面加入自增
                seqRequest(i+1,limit)
            }
        });
    });

    req.on('error',function(err) {
        console.log('problem with request: ' + err.message);
    });
}

seqRequest(0,10)

 

相关文章:

  • 2021-10-10
  • 2022-12-23
  • 2021-04-17
  • 2021-08-23
  • 2021-09-15
  • 2022-12-23
  • 2021-11-28
  • 2021-04-25
猜你喜欢
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
相关资源
相似解决方案