您的位置:首页 > 理论基础 > 计算机网络

如何判断一个网络路径是不是有效路径

2010-07-11 16:29 134 查看
http://blog.csdn.net/octverve/archive/2007/09/25/1800400.aspx

private
int GetUrlError(string curl)

{

int num = 200;

if
(this.method == 1)

{

HttpWebRequest request =
(HttpWebRequest) WebRequest.Create(new Uri(curl));

ServicePointManager.Expect100Continue = false;

try

{

((HttpWebResponse) request.GetResponse()).Close();

}

catch (WebException exception)

{

if (exception.Status != WebExceptionStatus.ProtocolError)

{

return num;

}

if (exception.Message.IndexOf("500") > 0)

{

return 500;

}

if
(exception.Message.IndexOf("401") > 0)

{

return 401;

}

if
(exception.Message.IndexOf("404") > 0)

{

num = 404;

}

}

return num;

}

}

当搜索引擎在请求某个Url时得到“404”状态回应时,便会知道该网页在网站内不复存在,从而在索引数据库中将其删除,——当然,这个删除过程有
可能需要很长时间——而当搜索引擎得到“200”状态回应时,则会认为该url是有效的,并将其回到到索引数据库中。

关于HTTP状态码,请参见

http://seo.highdiy.com/index.php/seo/custom-404-pages-and-error-code/


前本人曾研究过SEO,但是发现,过于技术化的SEO反道不好了{不好意思,话说远了}

GetUrlError("http://www.csdn.net/images/logo_csdn.gif")//判断其返回值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: