The below program will do so
using System;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string fileLocation = @"http://TestWebAPI/SampleText/sample.txt";
var serverResponse = GetServerResponse(fileLocation);
Console.WriteLine("URL Validity : {0} \n Server Response : {1}", serverResponse.Item1, serverResponse.Item2);
Console.ReadKey();
}
private static Tuple<bool,string> GetServerResponse(string fileLocation)
{
bool isValidURL = true;
string data = string.Empty;
using (WebClient client = new WebClient())
{
try
{
data = client.DownloadString(fileLocation);
}catch(WebException weX){
isValidURL = !isValidURL;
data = weX.Message;
}
}
return Tuple.Create<bool, string>(isValidURL, data);
}
}
}