簡體   English   中英

PowerShell Invoke-RestMethod超時

[英]PowerShell Invoke-RestMethod Timeout

我通過PowerShell命令檢查了許多服務(大約15個)。 如果該服務可用,則腳本運行時間很好,但是如果某些服務不可用,則腳本運行時間不好! 那么如何確定Invoke-RestMethod有特定的請求/響應時間呢? 我知道有一個參數-TimeoutSec 例如,如果我在4秒超時后未收到任何響應,則請求並拋出錯誤!

Invoke-RestMethod $uri -TimeoutSec

也許我誤解了參數-TimeoutSec

根據幫助:

> get-help Invoke-RestMethod -Parameter Timeoutsec

-TimeoutSec <Int32>
    Specifies how long the request can be pending before it times out. Enter a value in seconds. The default value, 0, specifies an indefinite time-out.

因此,該參數需要一個整數來表示超時時間。

Invoke-RestMethod $uri -TimeoutSec 4

請注意幫助中的警告:

A Domain Name System (DNS) query can take up to 15 seconds to return or time out. If your request contains a host name that requires resolution, and you set TimeoutSec to a value greater than zero, but less than 15 seconds, it can take 15 
seconds or more before a WebException is thrown, and your request times out.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM