zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

c#NetASP 远程 图片 判断 是否 存在
2023-06-13 09:14:02 时间
复制代码代码如下:

privateintGetUrlError(stringcurl)
{
intnum=200;
if(this.method==1)
{
HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(newUri(curl));
ServicePointManager.Expect100Continue=false;
try
{
((HttpWebResponse)request.GetResponse()).Close();
}
catch(WebExceptionexception)
{
if(exception.Status!=WebExceptionStatus.ProtocolError)
{
returnnum;
}
if(exception.Message.IndexOf("500")>0)
{
return500;
}
if(exception.Message.IndexOf("401")>0)
{
return401;
}
if(exception.Message.IndexOf("404")>0)
{
num=404;
}
}
returnnum;
}
}