首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell Invoke-RestMethod超时

PowerShell Invoke-RestMethod超时
EN

Stack Overflow用户
提问于 2018-12-13 14:34:49
回答 1查看 3.1K关注 0票数 0

我检查一些许多服务(环行交叉口15)是否有通过PowerShell命令提供的服务。如果服务可用,则脚本运行时间良好,但如果某些服务不可用,则脚本运行时间不佳!那么如何确定Invoke-RestMethod具有特定的请求/响应时间呢?我知道有一个参数-TimeoutSec。例如,如果我在4秒后没有得到响应,请求超时并抛出错误!

代码语言:javascript
复制
Invoke-RestMethod $uri -TimeoutSec

也许我误解了参数-TimeoutSec

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-13 21:07:32

根据帮助:

代码语言:javascript
复制
> 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.

因此,该参数需要一个整数来表示超时应该有多长。

代码语言:javascript
复制
Invoke-RestMethod $uri -TimeoutSec 4

请注意帮助中的警告:

代码语言:javascript
复制
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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53756212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档