我正在做一个采集新闻的软件,但是采集的图片的地址是加密的。
<img title="dvubb" src="showimg.asp?BoardID=15&filename=2012-4/201241010405374127.jpg" border="0" onload="imgresize(this);" alt="图片点击可在新窗口打开查看"/>
但是可以网页上可以另存为保存图片,地址解析可能是解析不出来了。有没有其他用的方法把图片下载下载?

解决方案 »

  1.   

    http响应头肯定包含了这些内容的
      

  2.   

    http响应头?能说的具体点吗?
    现在采集的信息的网址是
    http://www.chinaru.info/bbs/showimg.asp?BoardID=15&filename=2012-5/201251021431290253.jpg
    这里打开的话,是防止采集的图片,不是原来的图片。
      

  3.   

    构建HTTP头的时候加入 Referer 就可以了 别人做了防盗链你采集的时候 下载图片的时候 发送请求加入 Referer:www.chinaru.info
      

  4.   

                HttpWebRequest httpWrq = (HttpWebRequest)WebRequest.Create("http://www.chinaru.info/bbs/showimg.asp?BoardID=15&filename=2012-5/201251021431290253.jpg
    ");
                httpWrq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                httpWrq.Referer = "http://www.chinaru.info/";
                httpWrq.Headers[HttpRequestHeader.Cookie] = "suid=833661264";
                httpWrq.Headers[HttpRequestHeader.AcceptLanguage] = "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
                httpWrq.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                httpWrq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0";            using (HttpWebResponse httpWrp = (HttpWebResponse)httpWrq.GetResponse())
                {
                    using (Stream httpStream = httpWrp.GetResponseStream())
                    {
                                                           using (Image image = Image.FromStream(httpStream))
                                                            {
                                                                if (image.Width > 120 && image.Height > 90)
                                                                {
                                                                    string picName = System.Guid.NewGuid().ToString() + ".gif";
                                                                    image.Save(localDirectory + "\\" + picName);
                                                                }
                                                            }
                    }
                }
      

  5.   

                                                    HttpWebRequest httpWrq = (HttpWebRequest)WebRequest.Create("http://www.chinaru.info/bbs/showimg.asp?BoardID=15&filename=2012-5/201251021431290253.jpg
    ");
                                                    httpWrq.AllowAutoRedirect = false;
    httpWrq.Referer = "http://www.chinaru.info/";
     
                                                    using (HttpWebResponse httpWrp = (HttpWebResponse)httpWrq.GetResponse())
                                                    {
                                                        using (Stream httpStream = httpWrp.GetResponseStream())
                                                        {
                                                            using (Image image = Image.FromStream(httpStream))
                                                            {
                                                                if (image.Width > 120 && image.Height > 90)
                                                                {
                                                                    image.Save("图片路径");
                                                                }
                                                            }
                                                        }
                                                    }
    这样应该就可以了 
      

  6.   

    谢谢zhaoguanxu,看来以后还得多学习。