开发者

Started Playing with node.js. I have a question

I just created a HTTP server using this code fro the documentation:

var sys = require("sys"),
    http = require("http");

http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello World!");
    sys.puts('Connection');
}).listen(8080);

sys.puts("Server running at http://localhost:8080/");**
开发者_如何学Go

My question is, why when I go to localhost:8080 I got "connection" printed twice? is this a bug?


Your browser may be requesting the URL twice, once with a HEAD request and once with a GET request. Try using a simple interface, like telnet:

$ telnet localhost 8080
GET / HTTP/1.0

^]q

Leave a blank line after GET, and press Ctrl+]qEnter to get out.


two requests are sent to the server. The first request is automatically made by the browser, which requests favicon.ico, and of course, the second request is for the URL (localhost:8080).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜