asp.net(c#)判断远程图片是否存在
程序员文章站
2022-05-19 21:02:05
复制代码 代码如下: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;
}
}