我检查一些许多服务(环行交叉口15)是否有通过PowerShell命令提供的服务。如果服务可用,则脚本运行时间良好,但如果某些服务不可用,则脚本运行时间不佳!那么如何确定Invoke-RestMethod具有特定的请求/响应时间呢?我知道有一个参数-TimeoutSec。例如,如果我在4秒后没有得到响应,请求超时并抛出错误!
Invoke-RestMethod $uri -TimeoutSec也许我误解了参数-TimeoutSec
发布于 2018-12-13 21:07:32
根据帮助:
> 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.https://stackoverflow.com/questions/53756212
复制相似问题