[英]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.