首页 > 解决方案 > http POST 上的 net::ERR_SSL_PROTOCOL_ERROR 到快递服务器

问题描述

我正在尝试从反应客户端发布到本地主机上的快速服务器,我在谷歌浏览器中收到此错误。

反应应用程序:http://localhost:3000 快速应用程序:http://localhost:5000

POST https://localhost:5000/upload net::ERR_SSL_PROTOCOL_ERROR

我没有任何 SSL https 自签名证书,但我需要吗?我已经在我的 express 应用程序的一个目录中使用 create-react-app 来引导我的前端,所以我不知道某处的 webpack 设置是否试图将 http 作为 https 处理这个特定操作?

我没有为我的 express js 应用程序使用任何引导程序,我将在下面包含我的服务器文件以供参考。

const express = require ('express')
const bodyParser = require ('body-parser')
const port = 5000

var app = express()
var cors = require("cors");

app.use(cors())
app.use(bodyParser())
app.listen(port, () => console.log(`Example app listening on port ${port}!`))



app.post('/upload', (req,res)=>{
    if (req.files === null ){
        return res.status(400).json({message: 'no image uploaded please try again'})
    }else{
        const file = req.files.file
        let body = req.body
        res.json({body})
    } 
})

我知道关于这个问题有很多问题,但它们不相关或没有为我提供任何见解。我已经尝试确保端口也允许通过我的防火墙。我还清除了我的浏览器缓存。

标签: node.jsreactjsexpressssl

解决方案


这已在多个帖子中讨论过

默认情况下,您不能在浏览器上调用 localhost 请求,但您可以禁用安全性

在这里检查:在 Chrome 中禁用同源策略


推荐阅读