我有以下代码,旨在检查来自文件托管商的链接的可用性,如 rapidshare、extabit、turbobit........等。我在下面编写的代码总是返回 HttpStatusCode “OK”,因为链接实际上是有效的,但链接内的文件不可用或没有文件。有没有办法在不使用任何服务提供的任何 api 的情况下检查我想要的东西,我的意思是有没有一种使用 .Net 的方法可以让我做我想做的事?
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;
}