powershell - 重新检查 URL 三次以查找 Web 异常案例 powershell
问题描述
$status_wait =1
Do{
$https_request= invoke_webrequest -uri "https:\\"
$https_status = [int]http_request.statuscode
If($($_.categoryinfo.reason) -eq "webexception") {
Start-sleep -secounds 30
$status_wait+=1
}
Elseif($http_status -eq 200) {
Write-host "URL is up"
}
}Untill (status_wait -eq 3)
解决方案
您正在寻找这样的东西吗?
#Remove-Variable * -ErrorAction SilentlyContinue
$url = "www.yourtargetsite.com"
function try-webrequest($url){
try{
return (Invoke-WebRequest -uri $url -ErrorAction Stop)
}catch{
return $_
}
}
$wr = try-webrequest $url
if ($wr.statuscode -ne 200){
If($wr.categoryinfo.reason -eq "webexception"){
$count = 1
while($count -lt 4){
"Retrying...$count"
$count++
if ((try-webrequest $url).statuscode -eq 200){break}
sleep -seconds 30
}
}else{
#In case you want to handle any other exception
"The link is down NOT due to webexception"
}
}else{
"The link's up"
}
PS:我刚刚开始在stackoverflow上回答。我很想听听您的反馈。
推荐阅读
- selenium - 在没有部署和外部服务的情况下,在持续集成管道中测试所有隔离的 Web 应用程序
- kml - KML 线串长度
- python - 有哪些方法可以直接通过 django admin 更改站点的横幅图像?
- javascript - 来自mysql数据库的PHP动态图表数据
- html - 为什么我的 html 图像 scr 搜索的是 url 而不是我的目录?
- visual-studio - unity Camera 垂直滚动效果
- java - SASL_SSL 安全协议如何工作?客户端是否验证服务器(X.509 证书)?
- android - 有没有一种有效的方法将 Firebase 数据存储在 arraylist 中然后读取它?
- bash - 在 IFS 命令后读取时,奇怪的错误值对于基础来说太大了
- deserialization - YamlDotNet 可以反序列化为动态对象图吗?