欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-11-23 17:34:27
复制代码 代码如下:private int geturlerror(string curl) { int num = 200; if(this.method==1) { h...
复制代码 代码如下:

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