mirror of
https://github.com/fergalmoran/podnoms.git
synced 2026-01-23 00:48:09 +00:00
27 lines
785 B
C#
Executable File
27 lines
785 B
C#
Executable File
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PodNoms.Api.Utils
|
|
{
|
|
public class HttpUtils
|
|
{
|
|
public static async Task<string> DownloadFile(string url, string file="")
|
|
{
|
|
if (string.IsNullOrEmpty(file))
|
|
file = System.IO.Path.GetTempFileName();
|
|
|
|
using (var client = new HttpClient())
|
|
{
|
|
using (var response = await client.GetAsync(url))
|
|
{
|
|
using (var content = response.Content)
|
|
{
|
|
byte[] result = await content.ReadAsByteArrayAsync();
|
|
System.IO.File.WriteAllBytes(file, result);
|
|
}
|
|
}
|
|
}
|
|
return file;
|
|
}
|
|
}
|
|
} |