Пример #1
0
		public async Task<bool> DownloadFromUrlAsync(string url, string targetFile) {
			HttpClient httpClient = new HttpClient();
			HttpResponseMessage response = await httpClient.GetAsync(url);
			if (response.IsSuccessStatusCode) {
				filesystem.HttpContentToFile(response.Content, targetFile);
				return true;
			}
			return false;
		}
Пример #2
0
        public async Task <bool> DownloadFromUrlAsync(string url, string targetFile, string authentication)
        {
            HttpClient httpClient = new HttpClient();

            if (authentication != null)
            {
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authentication);
            }
            HttpResponseMessage response = await httpClient.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                string targetDir = targetFile.Substring(0, targetFile.LastIndexOf('/'));
                Directory.CreateDirectory(targetDir);
                await filesystem.HttpContentToFile(response.Content, targetFile);

                return(true);
            }
            return(false);
        }