Timeout error when running Invoke-RestMethod

心已入冬 提交于 2019-12-19 03:12:34

问题


I'm running the Invoke-RestMethod on PowerShell to invoke a Web API method. It works but after a minute or so, I get a timeout error. I'd really like for PowerShell to wait until the invoked method has completed. How do I do this? Thanks for any help. John

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

回答1:


According to Technet documentation for the Invoke-RestMethod cmdlet, there is a time-out argument you can append to your call. It is supposed to default to indefinite but there is a user complaining that it defaults to 100 seconds.

I can't see all of your code but, to specify a time-out of 2 minutes, your call should look like this:

Invoke-RestMethod -Uri "http://corloclaf2/api/Automation/GetAutomation?test" -TimeoutSec 120


来源:https://stackoverflow.com/questions/26993943/timeout-error-when-running-invoke-restmethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!