Express post请求给出ERR

编程入门 行业动态 更新时间:2024-10-19 06:27:09
本文介绍了Express post请求给出ERR_EMPTY_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个node.js和express.js网络应用程序,并且在发送请求超过2分钟后不能正常工作。 发生什么事是在2分钟后我的 express 路由被重新呼叫,然后,再过2分钟(总共4分钟),我在该帖子请求的网络标签中收到此错误:

I'm building a node.js and express.js web app and it doesn't works as expected when a post request takes longer than 2 mins. What happens is that after 2 mins my express route is re-called and then, after another 2 mins (4 mins in total) I get this error in the network tab for that post request:

net :: ERR_EMPTY_RESPONSE

net::ERR_EMPTY_RESPONSE

我读到 express 的默认超时设置为2分钟,但这仅适用于获取请求...

I read that express has a default timeout set to 2 mins, but that applies only to get requests...

这是我的路由:

const router = express.Router(); router.post('/', authenticate, async (req, res) => { console.log('here'); setTimeout(function() { res.status(201).json({success: true}); }, 400000); })

当我发送帖子请求时,它会将这里打印到控制台,然后再次打印这里

It prints here to the console when I make the post request, and then it prints again here after 2 minutes.

这是我的索引

const app = express(); app.use(bodyParser.json({limit: '50mb'})); const compiler = webpack(webpackConfig); app.use(webpackMiddleware(compiler, { hot: true, publicPath: webpackConfig.output.publicPath, noInfo: true })); app.use(webpackHotMiddleware(compiler)); app.get('/*', (req, res) => { res.sendFile(path.join(__dirname, './index.html')); }); app.listen(3000, () => console.log('Running on localhost:3000')); app.timeout = 700000;

自面临这个问题以来,已经有2周了,任何想法或解决方案都会帮助我许多。如果我需要提供更多的细节,请让我知道。

There are already 2 weeks since I'm facing this issue and any ideas or solutions would help me a lot. Please let me know if I need to provide more details.

推荐答案

我解决了我的问题,删除了网页浏览器的超时,如下所述: github/expressjs/express/issues/2174

I fixed my issue by removing the web browser's timeout as explained here: github/expressjs/express/issues/2174

更多推荐

Express post请求给出ERR

本文发布于:2023-10-11 23:01:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Express   post   ERR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!