C# webclient 下载文件时候出错
//作用是下载某个网站上的网页图标Uriuri=newUri(txtUrl.Text);System.Net.WebClientDownloadIcon=newWebCl...
//作用是下载某个网站上的网页图标 Uri uri = new Uri(txtUrl.Text); System.Net.WebClient DownloadIcon=new WebClient (); string downloadIconFilepath = Application.StartupPath + "\\webIcon\\" + uri.Host.Replace(".","") + ".ico"; // try { //DownloadIcon.DownloadFile(uri.GetLeftPart(UriPartial.Authority) + "/favicon.ico",downloadIconFilepath); } // catch { } 当下载 http://china.alibaba.com/favicon.ico 时候,出现错误,服务器错误(503) 其他网站大部分可以下载,为什么
展开
展开全部
//作用是下载某个网站上的网页图标 Uri uri = new Uri(txtUrl.Text); System.Net.WebClient DownloadIcon=new WebClient (); DownloadIcon.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"); string downloadIconFilepath = Application.StartupPath + "\\webIcon\\" + uri.Host.Replace(".","") + ".ico"; DownloadIcon.DownloadFile(uri.GetLeftPart(UriPartial.Authority) + "/favicon.ico",downloadIconFilepath);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询