node.js - nodejs读取远程地址,有些没有执行的原因
天蓬老师
天蓬老师 2017-04-17 14:35:23
0
1
239

var request = nodeRequire("request");

dlog('标记1');
request.head(src, function(err, res_req, body){
    dlog('标记2');
                
}).on('error', function(err) {
    dlog('标记3');
    console.log(err)
});

标记1输出230次,标记2输出202次,标记3是0次,那意思就是有一些丢失了,最可能的原因是什么。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
Peter_Zhu

......
request.head(src, function(err, res_req, body){
......
}).on( 'error', function(err) {

Don’t you think it’s strange, why are there err in the parameters in both places? What’s the difference between these two err? Where exactly should errors be handled?

So the questioner should read the document carefully. There are two writing methods to choose from:

var request = nodeRequire("request");

dlog('标记1');
request.head(src, function(err, res_req, body){
    if (err) {
        dlog('标记3');
        return;
    }
    dlog('标记2');
})

or

var request = nodeRequire("request");
dlog('标记1');
request.head(src)
.on('response', function (res) {
    dlog('标记2');
})
.on('error', function (err) {
    dlog('标记3');
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!