I saw the following code in stackoverflow :
$uri = "http://google.com"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$json = $wc.DownloadString($uri)
And it is working fine , but what I am wandering for, is that somehow I could store the status code of the URL I am hitting.
Actually when I am hitting a URL having status 404 , it is returning a exception for same.
Can anyone help me regarding how I can store the status or even if I can store the exception it is returning back.
This should be a good starting point for you:
Then you can check
$conn
for connection details.$out
will have the status, returns, etc.$out.StatusCode = 200
in this example.