/// <summary> /// 下载字节的文件 /// </summary> /// <param name="param">参数</param> /// <returns>返回当前本地路径</returns> public static string DownloadBytesFile(HttpClientDownload param) { var rs = Request(param).ToBytes(); var _path = $"{ param.LocalFolderPath }\\{param.LocalFileName}"; File.WriteAllBytes(_path, rs); return(_path); }
/// <summary> /// 下载文件 /// </summary> /// <param name="param"></param> /// <returns></returns> public static string DownloadFile(HttpClientDownload param) { using (var client = new WebClient()) { if (param.Headers != null && param.Headers.Count > 0) { foreach (var item in param.Headers) { client.Headers.Add(item.Key, item.Value); } } var _path = $"{ param.LocalFolderPath }\\{param.LocalFileName}"; client.DownloadFile(param.Url, _path); return(_path); } }
/// <summary> /// 异步下载文件 /// </summary> /// <param name="param"></param> /// <returns></returns> public static async Task <string> DownloadFileAsync(HttpClientDownload param) { return(await Task.Run(() => { return DownloadFile(param); })); }