Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell:如何确定Invoke WebRequest是否已超时?_Powershell_Invoke Webrequest - Fatal编程技术网

PowerShell:如何确定Invoke WebRequest是否已超时?

PowerShell:如何确定Invoke WebRequest是否已超时?,powershell,invoke-webrequest,Powershell,Invoke Webrequest,当Invoke WebRequest超过-TimeoutSec参数设置的时间限制时,我需要生成一些输出。在这种情况下,如何构建运行的If条件 换言之;什么代替了?????在下面的示例中?: Try { Invoke-RestMethod -Uri $Uri -contentType "application/json" -Method Post -Headers $Headers -Body $Body -TimeoutSec 8 } Catch { If (??

当Invoke WebRequest超过-TimeoutSec参数设置的时间限制时,我需要生成一些输出。在这种情况下,如何构建运行的If条件

换言之;什么代替了?????在下面的示例中?:

Try {
  Invoke-RestMethod -Uri $Uri -contentType "application/json"
   -Method Post -Headers $Headers -Body $Body -TimeoutSec 8
}
Catch {
 If (?????) {
    Write-Host "the request timed out..."
  }
}

在Windows PowerShell中,引发的异常将是
[System.Net.WebException]
,其
状态
字段设置为
超时

try{
  Invoke-WebRequest 'http://hostname.fqdn/really/slow/endpoint/' -TimeoutSec 3 -UseBasicParsing
}
catch [System.Net.WebException] {
  if($_.Exception.Status -eq 'Timeout'){
    # the request timed out
  }
  # something else went wrong during the web request
}

在Windows PowerShell中,引发的异常将是
[System.Net.WebException]
,其
状态
字段设置为
超时

try{
  Invoke-WebRequest 'http://hostname.fqdn/really/slow/endpoint/' -TimeoutSec 3 -UseBasicParsing
}
catch [System.Net.WebException] {
  if($_.Exception.Status -eq 'Timeout'){
    # the request timed out
  }
  # something else went wrong during the web request
}

哪个版本的PowerShell?我在此特定设备上使用版本5,但如果需要可以升级。哪个版本的PowerShell?我在此特定设备上使用版本5,但如果需要可以升级。