Files
podnoms/server/Utils/HttpUtils.cs
Fergal Moran 0d5778bf90 LE
2018-03-13 21:51:08 +00:00

27 lines
785 B
C#

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;
}
}
}