在我的浏览器中获取服务器禁止错误

时间:2016-05-25 08:48:18

标签: node.js

我刚开始探索node.js.在我的Windows服务器上安装了msi文件。我的代码在命令窗口中返回预期的输出

var http = require("http");

http.createServer(function (request, response) {

// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at `http://127.0.0.1:8081/`');

但是当我在浏览器中输入http://127.0.0.1:8081/时,我得不到任何输出。当我看到控制台时,我得到以下错误

Failed to load resource: the server responded with a status of 403 (Forbidden)

我错了怎么解决?我正在关注此link

2 个答案:

答案 0 :(得分:14)

可能就像我目前的PC一样,你也必须运行迈克菲或其他一些程序已经在使用端口8081,你有两个选择:

  • 停止McAfee或该端口上运行的其他程序
  • 侦听节点服务器上的其他端口

答案 1 :(得分:1)

var http = require("http");

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(300);

console.log('Server running at http://127.0.0.1:300/');

我从8081把它改为300并且它有效。

http://127.0.0.1:300/此网址提供所需的输出。