运行Invoke-RestMethod时出现超时错误

bea*_*man 6 powershell-3.0 asp.net-web-api

我在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
Run Code Online (Sandbox Code Playgroud)

Sha*_*neC 13

根据Invoke-RestMethod cmdlet的Technet文档,您可以将一个超时参数附加到您的调用中.它应该默认为无限期但有一个用户抱怨它默认为100秒.

我看不到你的所有代码,但是,为了指定2分钟的超时,你的调用应该是这样的:

Invoke-RestMethod -Uri "http://corloclaf2/api/Automation/GetAutomation?test" -TimeoutSec 120
Run Code Online (Sandbox Code Playgroud)

  • 它没有更多`timeout`参数.请改用"TimeoutSec". (3认同)