khi thực hiện http.request
có 2 sự kiện gây lỗi: request.on('error')
và response.on('error')
.sự khác biệt giữa request.on ('error') và response.on ('error')
Tôi không thể thấy sự khác biệt vì cả hai lỗi đến từ máy chủ web.
sự khác nhau giữa thisError
và thatError
là gì?
var request = http.request({hostname:"example.com"}, function(response){
response.on('error', function(thisError){
//what's the difference between thisError <<<<<<
});
});
request.on('error, function(thatError){
//and thatError <<<<<
});
'request' và' response' là cả hai luồng có thể ghi. Các luồng có thể ghi có thể phát ra các sự kiện lỗi: https://nodejs.org/api/stream.html#stream_event_error_1. Từ quan điểm đó, không có sự khác biệt. –
Có, cả hai đều triển khai luồng api, có nghĩa là chúng có thể phát ra '' 'lỗi'''. @FelixKling '' 'response''' thực sự là [IncommingMessage] (https://nodejs.org/api/http.html#http_http_incomingmessage) là' '' ReadableStream'''. –
@EdinM: Ah, tôi chỉ xem https://nodejs.org/api/http.html#http_class_http_serverresponse. –