I am in a company network. In this network i can't ping external websites by IP. I can only call them by url like the browser does. Thats why i use WebRequest to see if Internetconnection is established.
When i try to call "www.google.com" i got a "(407) Proxyauthentification required"
This Programm should be used on many pcs. So i dont want to set a Credential User and Password hardcoded in the Code.
This is my Code:
try
{
var uriBuilder = new UriBuilder(_URL);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);
request.Timeout = 1000;
//request.Accept = "*/*";
WebProxy proxy = new WebProxy("14*.***.***.***:8080");
//request.UseDefaultCredentials = true; //Dont work
//proxy.Credentials = System.Net.NetworkCredential(); //Dont work
proxy.Credentials = CredentialCache.DefaultNetworkCredentials; //dont work too
request.Proxy = proxy;
request.PreAuthenticate = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
_PingByURL = response.StatusCode == HttpStatusCode.OK;
}
catch
{
_PingByURL =false;
}
And my app.cfg:
<system.net>
<defaultProxy enabled ="true" useDefaultCredentials = "true">
<proxy usesystemdefault ="True" bypassonlocal="True"/> <!--True must written in capital Letters-->
</defaultProxy>
</system.net>
How can i solve error "(407) Proxyauthentification required"? Or is there a better way to check if Internetconnection is established through proxy without pinging it?