node.js: how to stop an already started http request

后端 未结 1 1477
刺人心
刺人心 2020-12-30 22:18

We use request to make http requests with node.js. We would like to give the user an opportunity to abort the request when he decides. That means we have to trigger the abor

相关标签:
1条回答
  • 2020-12-30 22:58

    The request function returns a request object. Just call abort() on that?

    var r = request({uri: 'http://stackoverflow.com'  }, function (error, response, body) {
        console.log('url requested ') ;
        if (!error){
            console.log(body);
        }
        else
        {
            console.log(error);
        }
    });
    
    r.abort();
    
    0 讨论(0)
提交回复
热议问题