using System;
using System.Net;
namespace RSSFeeder.Helpers{
/// <summary>
/// Checks whether internet connection is available by trying to download the homepage of
/// RSS Feeder. If successfully downloaded, then it's good to go for RSS Feed download.
/// </summary>
public class ConnectionHelper
{
private const string URL_TO_CHECK = "http://rssfeederdotnet.sourceforge.net/index.php?";
public static bool HasConnection()
{
try
{
// Create a unique URL to check for
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(new Uri( URL_TO_CHECK + DateTime.Now.Ticks.ToString() ) );
using( HttpWebResponse response = (HttpWebResponse) request.GetResponse() )
{
if( response.StatusCode == HttpStatusCode.OK )
return true;
else
return false;
}
}
catch
{
return false;
}
}
}
}
|