如何判断一个网络路径是不是有效路径
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;
}
}
{
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")//判断其返回值
好的代码像粥一样,都是用时间熬出来的
分类:
Delphi
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)