以前所有的图片都可以通过使用
从不同的网站下载 var request = WebRequest.Create(url.AbsoluteUri) as HttpWebRequest;
但是现在,我遇到了一个网站
http://www.euroman.dk/gadgets - og design/det onsker - vi os/skyd - 360 -视频-地中海- 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
谁能告诉我原因是什么?您的站点需要一个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);
}
可以设置更大的值
request.Timeout = 5000;
request.ReadWriteTimeout = 20000;