首页 > 解决方案 > Express 服务器导致错误“此站点无法提供安全连接 localhost 发送了无效响应”

问题描述

我正在尝试使用Express制作一个简单的 hello world 类型的服务器。这是我的代码:

const express = require("express");
const app = express();

app.get("/",function(request, response){//what to do when someone make get request to the homepage or route
  console.log(request);
  response.send("hello");
});

app.listen(3000, function(){
  console.log("server is listening at port 3000");
});

当我运行程序时,我在命令提示符下看到了这个:

server is listening at port 3000

但是当我通过浏览器访问它时 https://localhost:3000我得到了一个错误:

此站点无法提供安全连接 localhost 发送了无效响应。尝试运行 Windows 网络诊断程序。ERR_SSL_PROTOCOL_ERROR

我希望浏览器hello按照我上面的方法看到,response.send("hello")

标签: node.jsexpress

解决方案


您需要改为通过HTTP协议访问它。尝试连接到http://localhost:3000而不是https://localhost:3000.


推荐阅读