2013-05-30 33 views
0

以前,所有的圖片都是從不同的網站下載使用圖像沒有被C#,WebRequest.Create(url.AbsoluteUri)下載爲HttpWebRequest;

var request = WebRequest.Create(url.AbsoluteUri) as HttpWebRequest; 

但現在,我遇到了一個網站

http://www.euroman.dk/gadgets-og-design/det-onsker-vi-os/skyd-360-video-med-din-iphone/

這個圖片的URL是不是下載

http://www.euroman.dk/imagecropper.ashx?f=%2fUpload%2feuroman-dk%2fgadgets-og-design%2f2013%2520maj%2fthedot_01.jpg&w=643&h=405&m=1

有人可以建議我請問是什麼原因?

回答

0

您的網站預計的User-Agent頭。

string url = "http://www.euroman.dk/imagecropper.ashx?f=%2fUpload%2feuroman-dk%2fgadgets-og-design%2f2013%2520maj%2fthedot_01.jpg&w=643&h=405&m=1"; 
using (WebClient wc = new WebClient()) 
{ 
    wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"; 
    byte[] data = wc.DownloadData(url); 
} 
0

pehaps設置timout具有更大的價值

request.Timeout = 5000; 
request.ReadWriteTimeout = 20000;