http POST 上的 net::ERR_SSL_PROTOCOL_ERROR 到 Express 服务器

mon*_*ece 9 ssl node.js express reactjs

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

反应应用程序:http://localhost:3000 表达应用程序:http://localhost:5000

POST https://localhost:5000/upload net::ERR_SSL_PROTOCOL_ERROR
Run Code Online (Sandbox Code Playgroud)

我没有任何 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})
    } 
})
Run Code Online (Sandbox Code Playgroud)

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

小智 12

我遇到了同样的问题,并将 URL 更改为http://localhost:5000/upload而不是使用 https://localhost:5000/upload。

  • 我犯了同样的错误,我的问题通过在 https 中删除 s 解决 (2认同)

Cha*_* dB 1

这已在多个帖子中讨论过

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

检查此处:在 Chrome 中禁用同源策略