在Powershell中调用Rest API,然后等待响应

问题描述

我是PowerShell的新手。我正在使用Invoke-RestMethod在一个powershell脚本中运行多个rest API调用,第二个rest api调用返回200,但它无法完成所需的操作。似乎失败了,因为第一个API端点尚未完成工作。

因为当我在单独的脚本中分别运行第二个api时,它运行良好。 Powershell invoke-rest方法功能中是否存在异步并等待

当前代码


try {
    #First Rest API It works fine
    Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body  
}
catch {
    Write-Host "Failed"
    
}

try {
    #Second Rest API This returns 200 but does not do the work and if I run this API in a separate script
    #It runs fine in a separate script
    Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body  
}
catch {
    Write-Host "Failed"  
}

只想看看我是否可以等待第一种休息方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)