简体   繁体   中英

net::ERR_SSL_PROTOCOL_ERROR on http POST to express server

I'm trying to post from a react client to an express server on localhost and I get this error in google chrome.

react app: http://localhost:3000 express app: http://localhost:5000

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

I don't have any SSL https self signed certificate, but do I need to? I have used create-react-app inside a directory within my express application to bootstrap my front-end so I'm unaware if maybe a webpack setting somewhere is trying to handle http as https for this particular operation?

I haven't used any bootstrapping for my express js application and I'll include my server file below for reference.

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})
    } 
})

I know there are a fair few questions on this issue but they weren't relevant or didn't provide me any insight. I have tried making sure the ports are allowed through my firewall aswell. I have also cleared my browser cache.

This has been discussed in multiple posts

By default you cannot call localhost request on browsers but you can disable the security

Check here : Disable same origin policy in Chrome

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

I also faced the same issue and I changed the URL to http://localhost:5000/path instead of using https://localhost:5000/path

It works for me.

I had the same issue but it was with WAGMI (react hooks for web3 dev) and instead of using "https://localhost:6969" (this was the RPC url for my local node) I used "http://localhost:6969" which worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM