I am using below code to check the url connectivity
$uri = 'https://blue-vrrp.company_name.com'
try
{
$response = Invoke-WebRequest -Uri $uri -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop
# This will only execute if the Invoke-WebRequest is successful.
$StatusCode = $Response.StatusCode
$StatusDescription = $Response.StatusDescription
}
catch
{
$StatusCode = $_.Exception.Response.StatusCode.value__
$StatusDescription = $_.Exception.Response.StatusDescription.value__
}
It gives status code 407 sometimes and sometimes blank. Getting different responses every time as below without try/catch block.
- "The underlying connection was closed: An unexpected error occurred on a send."
- "The remote server returned an error: (407) Proxy Authentication Required."
- Invoke-WebRequest :Access Denied (authentication_failed) Details:Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.
Please let me know if it's an issue with WebRequest module or it's an issue with URL it self.
Thanks.