我正在尝试从我的 nodejs 脚本中调用 rest API。我希望脚本不断重复调用这个 api,直到我得到一个肯定的结果。这是我想要做的,但我的脚本只是冻结了:
var success=0;
while(!success){
axios.post('http://localhost:2000/evaluate', {serviceName:"s1"})
.then((response)=>{
if(response.data==1){
success=1; //desired response, quit the loop
res.send('1')
}
else{ //not the desired response, keep trying
res.send('0')
}
}//end while loop
Run Code Online (Sandbox Code Playgroud)
基本上,如何进行重复的 API 调用,直到得到我想要的响应??
谢谢!