gpt4 book ai didi

node.js - Learnyounode http collect off 一个

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:58 25 4
gpt4 key购买 nike

我正在通过 learnyounode 教程学习 node.js,但一直停留在 HTTP-COLLECT 练习中。我想让我的代码在没有第三方程序帮助的情况下工作。它几乎可以正常工作,但由于某种原因,它没有从 learnyounode 从中吸取数据的任何源接收到第一个数据 block ,所以我的代码是错误的。到目前为止,这是我的代码:

http = require("http");
var info = [];

http.get(process.argv[2],function(res){
res.setEncoding('utf8');
res.on("data",function(input){
info.push(input);
});
res.on("error",console.error);
res.on("end",function(){
console.log(info.join(""));
});
});

终端输出:

1.    ACTUAL:  "As busy as a fossicker mate built like a bluey. As dry as a sickie piece of piss mad as a beauty. As cunning as a trackies with get a dog up ya muster. Gutful of mate's rate piece of piss lets get some battler."
1. EXPECTED: "402"

2. ACTUAL: "We're going bottlo also come a holden. Grab us a bradman no dramas he hasn't got a ironman. She'll be right nipper no dramas she'll be right sheila. Mad as a pav also he hasn't got a barbie. "
2. EXPECTED: "As busy as a fossicker mate built like a bluey. As dry as a sickie piece of piss mad as a beauty. As cunning as a trackies with get a dog up ya muster. Gutful of mate's rate piece of piss lets get some battler."

3. ACTUAL: ""
3. EXPECTED: "We're going bottlo also come a holden. Grab us a bradman no dramas he hasn't got a ironman. She'll be right nipper no dramas she'll be right sheila. Mad as a pav also he hasn't got a barbie. "

4. ACTUAL:
4. EXPECTED: ""

我看到了this在 SO 上发帖,但它并没有真正帮助我,因为 1) 我正在尝试按照练习提示中的说明使用 http.get() 和 2) 我的问题似乎与代理问题无关。任何提示/帮助将不胜感激,我不确定如何从这里修复代码。

最佳答案

D'oh...在仔细研究之后,我发现了问题所在:第一个数字不是我丢失的数据,它只是接收到的文本的字符长度。其实程序本身并没有什么问题。我通过在 console.log(info.join("")); 之前添加 console.log(info.join("").length); 来修复我的代码行。

关于node.js - Learnyounode http collect off 一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23457420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com