Files
podnoms/server/Utils/HttpUtils.cs
Fergal Moran 8d69c72b83 Merge Repos
2017-10-30 20:42:23 +00:00

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