当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net(c#)判断远程图片是否存在

ASP.NET
合理的网盟广告策略:如何规划与投放网盟广告
GoDaddy Backorder域名抢注经验分享
Google Analytics获得GOOGLE真正的收录网站数据指标
Visual Studio 2008 Team Suite简体中文正式版- 激活方法

ASP.NET 中的 asp.net(c#)判断远程图片是否存在


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 128 ::
收藏到网摘: n/a

不错的应用,大家可以拓展到,判断远程文件是否存在等功能
复制代码 代码如下:

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;
}
}