无法从网上下载图片 [英] Can't download image from web

查看:75
本文介绍了无法从网上下载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,



请帮帮我。



我正在尝试从网站下载图像。我尝试了很多方法,总是可以将图像下载到我的计算机上,但是当我尝试打开图像时,我得到了以下错误:"无法打开此图片,因为文件似乎已损坏,损坏了
或太大了"





我使用了其他时间使用过的代码总是很好,我不知道会发生什么。





这是图片的链接:


http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd: MS2MSD0330          2080 / is_not_main:1 / imageno:2



                       

  ; using(System.Net.WebClient client = new System.Net.WebClient())

           {



             client.DownloadFile(new Uri(" http:/ /www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330%202080/is_not_main:1/imageno:2"),@" c:\ temp\image251.jpg");



          }


(OR)


HttpWebRequest request =(HttpWebRequest)WebRequest.Create(" http://www.orange-book.com/细节/ obwfk53010 / contents_images / article_cd:MS2MSD0330                    2080 / is_not_main:1 / imageno:2");

            HttpWebResponse response =(HttpWebResponse)request.GetResponse();



            if((response.StatusCode == HttpStatusCode.OK ||

         response.StatusCode == HttpStatusCode.Moved ||

         response.StatusCode == HttpStatusCode.Redirect)) 

            {

              

               使用(Stream inputStream = response.GetResponseStream())

                using(Stream outputStream = File.OpenWrite(@" c:\ temp \ image15.png")))
                {

                    byte [] buffer = new byte [4096];

                    int bytesRead;

                   你是
                    {

                        bytesRead = inputStream.Read(buffer,0,buffer.Length);

                        outputStream.Write(buffer,0,bytesRead);

                    } while(bytesRead!= 0);

                }¥b $ b            }










解决方案

非常感谢,Castorix31


我尝试使用此链接,


<但是同样的错误。

为什么?,我不知道。


hello,

please help me.

i'm tryin gto download an image from a website. I tried a lot of methods and always I can download the image ti my computer, but when I try to open the image i get the folllowing error: "Can't open this icture because the file appears to damaged, corrupted or is too large"

I used a code that I used other times and allways worked fine, I don't know what happens.

this is the link to the image:

http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330                    2080/is_not_main:1/imageno:2

                                           

 using (System.Net.WebClient client = new System.Net.WebClient())
                    {

                        client.DownloadFile(new Uri("http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330%202080/is_not_main:1/imageno:2"), @"c:\temp\image251.jpg");

                   }

(OR)

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330                    2080/is_not_main:1/imageno:2");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if ((response.StatusCode == HttpStatusCode.OK ||
                response.StatusCode == HttpStatusCode.Moved ||
                response.StatusCode == HttpStatusCode.Redirect)) 
            {
              
                using (Stream inputStream = response.GetResponseStream())
                using (Stream outputStream = File.OpenWrite(@"c:\temp\image15.png"))
                {
                    byte[] buffer = new byte[4096];
                    int bytesRead;
                    do
                    {
                        bytesRead = inputStream.Read(buffer, 0, buffer.Length);
                        outputStream.Write(buffer, 0, bytesRead);
                    } while (bytesRead != 0);
                }
            }



解决方案

So thanks , Castorix31

I try with this link,

But the same error.
Why?, I don't know.


这篇关于无法从网上下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆