2014-11-18 3 views
6

Sto eseguendo Invoke-RestMethod su PowerShell per richiamare un metodo API Web. Funziona ma dopo un minuto circa, ottengo un errore di timeout. Mi piacerebbe molto che PowerShell attenda fino al completamento del metodo invocato. Come faccio a fare questo? Grazie per l'aiuto. JohnErrore di timeout durante l'esecuzione di Invoke-RestMethod

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 

risposta

9

Secondo Technet documentation for the Invoke-RestMethod cmdlet, c'è un argomento time-out è possibile aggiungere alla tua chiamata. Si suppone che l'impostazione predefinita sia indefinita, ma c'è un utente che si lamenta del fatto che è impostato su 100 secondi.

non riesco a vedere tutto il codice, ma, per specificare un time-out di 2 minuti, la chiamata dovrebbe essere simile a questo:

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

Grazie Shane, che ha fatto il trucco! Molto apprezzato. – bearaman

+3

Non ha più il parametro 'timeout'. Usa invece "TimeoutSec". –

+0

Ho aggiornato la mia risposta in modo conforme – ShaneC

Problemi correlati