简体   繁体   中英

JavaScript https get request

a get request to the address https://api.steampowered.com/ISteamApps/GetAppList/v2/?format=json is sent too long with this code:

https.get("https://api.steampowered.com/ISteamApps/GetAppList/v2/?format=json", (res) => 
    {
        res.setEncoding("utf8");
        let bodyCount = "";
        res.on("data", (dataCount) => {
        bodyCount += dataCount;
        });
        res.on("end", () => {
        bodyCount = JSON.parse(bodyCount);
        console.log(bodyCount);
        });
});

The process takes up to several seconds, so how to make it happen faster?

In case anyone is wondering how I solved the problem:

setInterval(() =>{
    https.get("https://api.steampowered.com/ISteamApps/GetAppList/v2/?format=json", (res) => {
        res.setEncoding("utf8");
        let body ="";
        res.on("data", (dataCount) => {
            body += dataCount;
        });
        res.on("end", () =>{
           fs.writeFile('./steamdatabase.txt', body, (err) => {
  if (err) {
    console.error(err)
    return
  }
        });
});
});
}, 86400000);

...

 fs.readFile('./steamdatabase.txt', (err, data) => {
                    if (err) {
                       console.error(err)
                       return
                    }

            let body = JSON.parse(data);
            for(let i = 0;i<body.applist.apps.length;i++){
                if(body.applist.apps[i].name == generateParameter(args)) appidGame = body.applist.apps[i].appid;
                }
            if(appidGame) appInfo(appidGame,mess);
            });

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