learnyounodeのHTTPクライアント割り当てに取り組んでいます。response.on( "end"、コールバック)のデータをresponse.on( "data"、コールバック)のデータとは異なる印字にするのはなぜですか?
私はコンソールがresponse.on( "data"、callback)からのデータを出力している間に、response.on( "end"、callback)全体の反応。ここで
は、前者のために私のコードです:
var http=require("http");
http.get(process.argv[2], function(response){
var str;
response.setEncoding('utf-8');
response.on("error",function(error){
console.log(error);
});
response.on("data", function(data){
str=data;
});
response.on("end", function(){
console.log(str);
});
}).end();
結果は示しています
ACTUAL EXPECTED
───────────────────────────────────────────────────────────────────────
"Veg out" != "Bodgy"
"" != "Chuck a sickie"
!= "Cook"
!= "Dag"
!= "Larrikin"
!= "Hit the turps"
!= "Counter meal"
!= "Hottie"
!= "Veg out"
!= ""
──────────────────────────────────────────────────────────────────────
response.on( "データ"、コールバック)のためのコードはこれです:
var http=require("http");
http.get(process.argv[2], function(response){
response.setEncoding('utf-8');
response.on("error",function(error){
console.log(error);
});
response.on("data", function(data){
console.log(data);
});
}).end();
結果は次のとおりです。
ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────
"Amber fluid" == "Amber fluid"
"Ankle biter" == "Ankle biter"
"Bities" == "Bities"
"Slabs" == "Slabs"
"Captain Cook" == "Captain Cook"
"Galah" == "Galah"
"Battler" == "Battler"
"Sickie" == "Sickie"
"Chook" == "Chook"
"Going off" == "Going off"
"" == ""
────────────────────────────────────────────────────────────────────────────────
前者のコードは最後の要素のみを記録します。どうしてこれなの?
ありがとうございます!