$url = "https://example.com" $response = Invoke-WebRequest -Uri $url -UseBasicParsing if ($response.StatusCode -eq 200) { Write-Output "Request succeeded." } else { Write-Error "Request failed with status code: $($response.StatusCode)." } 尝试捕获更详细的错误信息: 使用-ErrorActio...
當遇到非成功 HTTP 訊息(404、500 等)時Invoke-WebRequest,它不會傳回任何輸出並擲回終止錯誤。 若要攔截錯誤並檢視StatusCode,您可以將執行封入區塊中try/catch。 PowerShell try{$Response=Invoke-WebRequest-Uri"www.microsoft.com/unkownhost"# This will only execute if the Invoke-WebReques...
StatusCode } catch { Write-Error $_.Exception.Message Write-Error $_.Exception.Response } 总结 以上是使用 PowerShell 的 Invoke-WebRequest 与GoDaddy API 交互时可能遇到的一些常见问题及其解决方法。确保身份验证正确、请求格式无误、处理速率限制,并根据需要启用详细的日志记录,以便快速定位和解决问题。...
StatusCode : 200 StatusDescription : OK Content : <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many speci..." RawContent : HTTP/1.1 200...
$StatusCode = $Response.StatusCode } catch { $StatusCode = $_.Exception.Response.StatusCode.value__ } $StatusCode 404 The terminating error is caught by the catch block, which retrieves the StatusCode from the Exception object.Example 8: Download multiple files at the same timeThe Invoke-...
StatusCode : 200 StatusDescription : OK Content : <!doctype html><html itemscope="" itemtype="http:///WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many speci..." ...
{ # 发送HTTP GET请求 $response = Invoke-WebRequest -Uri $url -Method Get # 输出响应的状态码和内容 Write-Output "URL: $url" Write-Output "Status Code: $($response.StatusCode)" Write-Output "Content: $($response.Content | Select-String -Pattern '<title>(.*?)</title>' -AllMatches |...
Hi All, I am executing the powershell script Invoke-webrequest for few sharepoint sites. Among 10 SharePoint sites, 1 sharePoint site gave the output as status code "200" and status description "ok". This is a separate…
StatusCode : 200 StatusDescription : OK Content : {"fact":"A cat's hearing is much more sensitive than humans and dogs.","length":60} RawContent : HTTP/1.1 200 OK Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding ...
roomId =$roomIDmarkdown =$string} Headers = @{'Authorization'="Bearer$WebexBotToken"'Accept'='application/json; charset=UTF-8''Accept-Charset'='UTF-8'} }$response=Invoke-WebRequest@requestif($response.StatusCode-eq200) {Write-Host"Webex Notification Sended"-ForegroundColorGreen ...