郑德才博客 记录学习,记录工作,学习知识分享!

asp.net判断图片地址是否存在

返回值为200的时候,为图片能正常显示

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;

   }

}

2013年7月25日 | 发布:郑德才博客 | 分类:博文调用 | 评论:0

发表留言: