Hello I am working on node js http request with a loop and its size is 1728 and its response is missing like it stuck at 1727 kindly help me I am trying to fix this problem for three days.
for ( let i = 0 ; i < playerLength ; i++ ) {
for ( let j = startYear ; j < currentYear ; j++ ) {
var playerSeasonData = {};
playerSeasonData.url = me.config.sport.url + league + '/v2/JSON/PlayerSeasonStatsByPlayer/'+ j +'/' + playerData[i].playerID;
playerSeasonData.method = 'GET';
playerSeasonData.headers = {};
playerSeasonData.headers = {'Ocp-Apim-Subscription-Key':'**********************'};
me.request( playerSeasonData ,function( error, response, data ){
count ++;
)};
}
}
The problem you are having is that your function is returning before all the http requests have been completed.
Consider promisifying me.request
via bluebird
and then return a Promise.all
. Here's an example: http://bluebirdjs.com/docs/api/promise.all.html
Did you try the simple solution of using <= instead of <. Hard to say from the code you are showing, but that might be the difference between 1728 & 1727.
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.