当响应长度超过16101时,节点Js HTTP响应崩溃

我正在使用节点JS HTTP请求。 当我的回复长度超过16101时,它会截断我的回应。 我收到如下有限的回应:

{"id_user":"133696"},{"id_u 

这不是一个分块的回应,它只有一次。 我想接收整个响应而不是截断。

我的节点版本是v0.10.36。

这是我的代码:

 var https = require('https'); var querystring = require('querystring'); postData.format = 'json'; postData.apikey = 'abcd'; jsonObject = querystring.stringify(postData); var postheaders = { 'Content-Type' : 'application/x-www-form-urlencoded', 'Content-Length' : Buffer.byteLength(jsonObject, 'utf8') }; if(callMethod == undefined){ callMethod = 'POST'; } var optionspost = { host : this.host, port : this.port, path : this.path, method : callMethod, headers : postheaders }; var reqPost = https.request(optionspost, function(res) { res.setEncoding('utf-8'); res.on('data', function(responseData) { //---->>> responseData containes truncated response if(callFunction != undefined && callFunction != null && callFunction != ''){ callFunction(responseData, relatedData);//****** calling success function **** } }); res.on('end', function() { }); }); reqPost.write(jsonObject); reqPost.end(); reqPost.on('error', function(e) { console.error(e); }); 

您的代码只需要一次data事件,但是Node可以多次触发它。 事实上,它可以多次启动它,因为它该死的请求。:)每次发生data事件,另一部分数据提供给你。 你知道,当end事件被触发时,没有更多的数据要消耗 – 这就是你应该处理数据和/或调用callback函数的地方。

由于响应基本上是可读stream,请查看Readable Stream的data事件 。