我正在 PowerShell 上运行 Invoke-RestMethod 来调用 Web API 方法。它有效,但大约一分钟后,我收到超时错误。我真的希望 PowerShell 能够等到调用的方法完成。
我该怎么做呢?
谢谢你的帮助。
约翰
PS C:\Test\TestScripts> .\Run_Automation 5.5.4.382.1
VERBOSE: GET http://server/api/Automation/GetAutomation?testName=5.5.4.382.1 with 0-byte payload
Invoke-RestMethod : The operation has timed out.
At C:\TeamCity\TeamCityScripts\Run_Automation.ps1:20 char:5
+ Invoke-RestMethod -Uri http://corloclaf2/api/Automation/GetAutomation?testNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId :WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
根据Invoke-RestMethod cmdlet 的 Technet 文档 http://technet.microsoft.com/en-us/library/hh849971.aspx,您可以在调用中附加一个超时参数。它应该默认为无限期,但有用户抱怨它默认为 100 秒。
我看不到您的所有代码,但是要指定 2 分钟的超时,您的调用应如下所示:
Invoke-RestMethod -Uri "http://corloclaf2/api/Automation/GetAutomation?test" -TimeoutSec 120
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)