C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
2017-04-24 18:44
489 查看
//如果下载失败会请求3次 string exep = ""; do { try { if (!Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } using (var wc = new WebClient()) { wc.Credentials = CredentialCache.DefaultCredentials; wc.Headers.Add(HttpRequestHeader.UserAgent, "anything"); wc.DownloadFile(strFullName, Dir + strFullName.Substring(strFullName.LastIndexOf('/') + 1)); } return true; } catch (System.Net.WebException ex) { //图片服务器上也存在也会报错 if (ex.Message == "An exception occurred during a WebClient request.") { exep = "occurred"; } else { exep = ""; } } catch (Exception ex) { LogMsg.WriteLogToApplicationFolderByMonth(ex.ToString() + "-------------------------------------FileURL:" + strFullName); return false; } } while (exep == "occurred"); return true;
图片在服务器存在,能够正常访问,但是下载的时候时不时会报“An exception occurred during a WebClient request.”
不知道如何处理,所以就做了一个循环,最多下砸3次。(目前可以解决下载的问题,因为这个问题是偶尔发生在某一个下载请求里,所以用了个循环请求直至3次请求下载完成)
相关文章推荐
- C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
- httpWebRequest WebClient下载慢的问题处理
- An exception occurred during a WebClient request
- 如何用HttpWebRequest下载gzip, deflate压缩的页面
- 用C#使用HttpWebRequest Post数据时如何保持Session
- 如何用HttpWebRequest下载gzip, deflate压缩的页面
- C#: Create a WebRequest with HTTPClient
- C#通过WebClient/HttpWebRequest实现http的post/get方法
- 如何用HttpWebRequest下载gzip, deflate压缩的页面
- An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informat
- 如何用HttpWebRequest下载gzip, deflate压缩的页面
- C# Httpwebrequest 连接数限制处理
- 转:C#通过WebClient/HttpWebRequest实现http的post/get方法
- C#: WebRequest和WebResponse下载文件示例
- C# webclient UploadStringAsync如何得到变量?
- 笨笨图片批量抓取下载 V0.2 beta[C# | WinForm | 正则表达式 | HttpWebRequest | Async异步编程]
- C# WebRequest WebClient Post请求 无乱码
- C# HttpWebRequest可断点上传,下载文件;SOCKET多线程多管道可断点传送大文件
- C# : WebRequest发起Http Post请求模拟登陆并cookie处理示例
- C# WebClient上传下载资料问题求助