0
    var tabProxy = new Array(
    '122.72.76.122'
    ,'124.240.187.79'
     );
 http.get ({
            host: tabProxy[selectorProxy],
            port: 80,
            path: baseurl + counter
        }, function (response) {
            try{
                var statusCode = response.statusCode;
                console.log (statusCode);
             }catch(e){
            console.log(e);
        }
    })

选择器代理=0;它可以工作,但 selectorProxy = 1; 应用程序崩溃:

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: socket hang up
    at createHangUpError (http.js:1417:15)
    at Socket.socketOnEnd [as onend] (http.js:1513:23)
    at Socket.g (events.js:175:14)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:870:14
    at process._tickCallback (node.js:415:13)

如何弥补这个错误(提取我的数组的这个 ip)?尝试捕获不起作用!

4

1 回答 1

4

您的 try/catch 不涵盖任何会引发错误的内容。更重要的是,您需要根据您的请求监听'error'事件。

var req = http.get(options, function (res) { ... });
req.on('error', function (err) {
    //handle error here
});
于 2013-04-02T13:10:34.193 回答