问题描述
我正在使用Express Framework.我正在尝试从服务器发送非常大的数据.客户端收到200 OK状态,但没有数据.即使我从服务器发送内容长度标头,它也会给出错误ERR_CONTENT_LENGTH_MISMATCH.我回复的内容长度为2102619.
I am using Express Framework. I am trying to send very large data from server. The Client receives 200 OK status but no data. Also it gives error ERR_CONTENT_LENGTH_MISMATCH even though I am sending the content-length Header from server. The content-length of my response is 2102619.
这是我用来发送回复的代码:
This is the code I used to send response:
var rowNew = JSON.stringify(row);
res.set({ 'Content-Length': rowNew.length });
return res.status(200).send(row);
还尝试将时间限制增加到很大:
Also tried increasing the time limit to a very large:
server.timeout = 300000;
推荐答案
看看以块和流的形式发送数据,而不是一次发送所有数据.
Take a look at sending data in chunks and streams instead of everything at once.
https://medium.freecodecamp. org/node-js-streams-您需要知道的一切-c9141306be93 https://carlosrymer.com/using-node-streams -to-handle-large-file-uploads-24c1a0141b9c
这篇关于NodeJ:如何从服务器向客户端发送非常大的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!