如何判断一个网络路径是不是有效路径
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.youkuaiyun.com/images/logo_csdn.gif")//判断其返回值