Esempio n. 1
0
        public static bool IsWebAccessible(Uri[] uriCheckList = null, NetProxy proxy = null, WebClientExNetworkType networkType = WebClientExNetworkType.Default, int timeout = 10000, bool throwException = false)
        {
            if (uriCheckList == null)
            {
                uriCheckList = new Uri[] { new Uri("https://www.google.com/"), new Uri("https://www.microsoft.com/") }
            }
            ;

            using (WebClientEx client = new WebClientEx())
            {
                client.Proxy       = proxy;
                client.NetworkType = networkType;
                client.Timeout     = timeout;

                Exception lastException = null;

                foreach (Uri uri in uriCheckList)
                {
                    try
                    {
                        client.OpenRead(uri);
                        return(true);
                    }
                    catch (WebException ex)
                    {
                        lastException = ex;
                    }
                }

                if (throwException)
                {
                    throw lastException;
                }
            }

            return(false);
        }
    }
 public WebClientWriteStream(WebClientEx webClient, WebRequest request)
 {
     _webClient     = webClient;
     _request       = request;
     _requestStream = request.GetRequestStream();
 }