查找动态调用的url中是否包含图像

本文关键字:是否 包含 图像 url 动态 调用 查找 | 更新日期: 2023-09-27 18:14:54

我有一个产品销售模块,其中产品从cj上传并保存到数据库..今天我注意到很少有记录包含图像url,但返回404(例如图像url:http://www.bridalfashionmall.com/images/satin-2.jpg)因此在中继器中没有显示图像。如何检查动态调用的url中是否有图像

查找动态调用的url中是否包含图像

sean建议的方法可以作为第一步。作为第二遍,你可以尝试加载流到图像,看看它是否实际上是图像?

 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(imageFilePath);
 request.Timeout = 5000;
 request.ReadWriteTimeout = 20000;
 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 System.Drawing.Image img = System.Drawing.Image.FromStream(response.GetResponseStream());
 // Save the response to the output stream
 Response.ContentType = "image/gif";
this one helped---
http://stackoverflow.com/questions/1639878/how-can-i-check-if-an-image-exists-at-http-someurl-myimage-jpg-in-c-asp-net

this one too worked
               try
                {
                    WebClient client = new WebClient();
                    client.DownloadData(ImageUrl);
                }
                catch
                {
                    imgPhoto.ImageUrl = ../User/Images/ResourceImages/Candychocolate1.jpg";//default image path
                }