public void DownloadFile(string url, string fileName) { try { var fileInfo = new FileInfo(fileName); if (fileInfo.Directory != null && !fileInfo.Directory.Exists) { fileInfo.Directory.Create(); } _logger.Debug("Downloading [{0}] to [{1}]", url, fileName); var stopWatch = Stopwatch.StartNew(); var webClient = new GZipWebClient(); webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgentBuilder.GetUserAgent()); webClient.DownloadFile(url, fileName); stopWatch.Stop(); _logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds); } catch (WebException e) { _logger.Warn("Failed to get response from: {0} {1}", url, e.Message); throw; } catch (Exception e) { _logger.Warn(e, "Failed to get response from: " + url); throw; } }
private string DownloadString(string url, ICredentials identity) { try { var client = new GZipWebClient { Credentials = identity }; client.Headers.Add(HttpRequestHeader.UserAgent, _userAgent); return client.DownloadString(url); } catch (WebException e) { _logger.Warn("Failed to get response from: {0} {1}", url, e.Message); throw; } catch (Exception e) { _logger.Warn(e, "Failed to get response from: " + url); throw; } }
private string DownloadString(string url, ICredentials identity) { try { var client = new GZipWebClient { Credentials = identity }; client.Headers.Add(HttpRequestHeader.UserAgent, _userAgent); return(client.DownloadString(url)); } catch (WebException e) { _logger.Warn("Failed to get response from: {0} {1}", url, e.Message); throw; } catch (Exception e) { _logger.Warn(e, "Failed to get response from: " + url); throw; } }