node.js - 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")
解决方案
您需要改为通过HTTP
协议访问它。尝试连接到http://localhost:3000
而不是https://localhost:3000
.
推荐阅读
- mysql - 在 MySQL/SQL 中按频率排序
- maven - maven JAR 可以在 hadoop 上运行吗?
- vba - 使用Word VBA,我可以将一个Form的代码模块分成两个代码模块吗?
- javascript - 我可以为 grid-template-rows / grid-template-columns 使用数字值吗?
- java - Java / 包含多个“.”的语句 运营商
- java - ARCore:如何检测照明不足?
- c# - 基于主机名的 ASP.NET Core 2.0 身份验证
- android - 模拟器在启动时冻结
- android - 使用Android P的ImageDecoder有什么用处和优势?
- javascript - React native - 使用 javascript 的 Webview - document.cookie