如何测试在 Node.js 中接收流/分块数据?
我一直在探索 node.js api,并且遇到了 HTTP 服务器的“data”事件。我的问题是:假设有一个像下面这样非常简单的应用程序,我如何发送数据并调试流?
var http = require("http");
http.createServer(function(req, res) {
req.setEncoding("utf8");
req.on("data", function(data){
console.log("request:\n" + data);
});
}).listen(3000, "127.0.0.1");
我尝试过使用telnet和curl来发送请求,但没有取得任何成功。谢谢大家!
I've been exploring the node.js api, and I ran across the "data" event for HTTP servers. My question is this: assuming a dead-simple app like below, how could I send data, and debug the stream?
var http = require("http");
http.createServer(function(req, res) {
req.setEncoding("utf8");
req.on("data", function(data){
console.log("request:\n" + data);
});
}).listen(3000, "127.0.0.1");
I've tried using telnet and curl to send requests, but I haven't had any success. Thanks all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我混淆了 HTTP 和 TCP。如果您编写 TCP 服务器,而不是 HTTP 服务器:
您可以轻松地通过 telnet(或 netcat)测试/调试到服务器的流数据:
It seems I was confusing HTTP and TCP. If you write a TCP server, rather than an HTTP server:
you can easily test/debug streaming data to the server via telnet (or netcat):