Debugging Unexpected Responses from Proxy
Test script used to troubleshoot an issue related. The overall problem involved connections through a proxy failing intermittently but the backend accessed directly would never report the same failures. We used this script to probe both endpoints every 120 seconds to try and pinpoint the problem reporting the IP address, response from both endpoints, and all the headers to better understand what was returning the failure.
Start-Transcript -Path "C:\temp\debug.txt" -Append
while (1)
{
Get-Date -Format "dddd MM/dd/yyyy HH:mm zzz"
Resolve-DnsName contoso1.com
Resolve-DnsName contoso2.com
$Site1Response = ""
$Site2Response =""
$FailureResponseSite1 =""
$FailureResponseSite2 =""
#mimicing a browser
$userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
try
{
$Site1Response = iwr https://www.contoso1.com -UserAgent $userAgent
}
catch
{
$FailureResponseSite1 = $_.Exception.Response
}
try
{
$Site2Response = iwr https://contoso2.com -UserAgent $userAgent
}
catch
{
$FailureResponseSite2 = $_.Exception.Response
}
Write-Host( "Site1 RESPONSE --------------")
$Site1Response.StatusCode
Write-Host( "Site2 RESPONSE --------------")
$Site2Response.StatusCode
Write-Host( "Site1 Failure RESPONSE --------------")
$FailureResponseSite1
$FailureResponseSite1.Headers.AllKeys
Write-Host( "Site2 Failure RESPONSE --------------")
$FailureResponseSite2
$FailureResponseSite2.Headers.AllKeys
$FailureResponse
Write-Host("------------------------------------------------------------------------------------------------")
Start-Sleep -Seconds 120
}