繁体   English   中英

如何使用节点js在循环内调用api

[英]how to call api inside loop using node js

I need to call API based on page number and on each and every page number API calling perform So I need to make API calling in loop based on page number.I uses request() for API Calling but when debug my code debug pointer is not将阻止响应而不得到响应。 我的代码如下,任何人都可以指导我吗?

for (var i = 1; i <= totalpages; i++)
  request.get(
    "https://idms.dealersocket.com/api/account/getaccountlist?token=" +
      dealertoken +
      "&LayoutID=2002313&PageNumber=" +
      i +
      "&accounttype=i&accountstatus=a,c,b,o,r,s,x",
    (err, res) => {
      console.log(res);
    },
  );

我建议安装axios并执行以下操作:

const axios = require('axios');

const sendGetRequest = async (url) => {
  const response = await axios.get(url);
  console.log(response);
}

for (var i = 1; i <= totalpages; i++) {
  const url = "https://idms.dealersocket.com/api/account/getaccountlist?token=" +
      dealertoken + "&LayoutID=2002313&PageNumber=" + i + "&accounttype=i&accountstatus=a,c,b,o,r,s,x"
  sendGetRequest(url);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM