2

我正在使用代码运行一个简单的 Node.JS 服务器:

require('http').createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
  res.end('<h1>Hi there world</h1>');
}).listen(3000);

它按预期工作。当我输入“http://localhost:3000”时,会出现标题“Hi there world”。

但是,当我使用 telnet 时:

telnet localhost 3000

我只收到消息:

Connecting To localhost...

防火墙已关闭。Telnet 连接到外部主机没有任何问题。

4

1 回答 1

4

Well, I'd guess your node.js server is waiting for you to issue a GET request. When it is waiting after the message Connecting to Localhost....

The telnet client doesn't visually indicate that it is connected. Just write your request and it should get entered.

Put your GET request in:

GET / HTTP 1.1
于 2012-10-30T13:56:47.587 回答