I have the following code which is intended to check availability of links from file hosters like rapidshare, extabit, turbobit……..etc. The code i written below always returns HttpStatusCode “OK” cause the link is actually valid, but the file inside the link is not available or there is no file. Is there a way to check for what i want without using any api provided by any service, i mean is there a way using .Net that will let me do what i want ?
private bool LinkChecker(string url)
{
string result = string.Empty;
Uri urlCheck = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlCheck);
request.Timeout = 15000;
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception err)
{
return false;
}
switch ((HttpStatusCode)response.StatusCode)
{
case HttpStatusCode.OK:
result = "Ok";
break;
case HttpStatusCode.BadGateway:
result = "No Internet";
break;
case HttpStatusCode.Forbidden:
result = "Link Not Found";
break;
case HttpStatusCode.NotFound:
result = "Link Not Found";
break;
}
if (result == "Ok")
return true;
else
return false;
}
It really depends on the hoster.
Some hosters return HTTP response with a proper code, but from my experience, most of them always return 200 OK. Many web site always return 200 OK even if page/file not found.
Some hosters returns HTTP redirect to a “file not found” page, so you can use that (your new URL will contain the text “filenotfound”.
But I think the most generic way to go is to look for certain text in the response body. That means that with high probability you will look for different text for each hoster, but I don’t really see any other way.
Hope it helps! 🙂