ace/Source/ACE.Server/Program_WebClient.cs
Ty Conner 0c0ca9c7a4
Update to .NET6 (#3739)
* Update to .NET6

* Update dockerfiles to NET6

* Update appveyor.yml

* Update ACE.DatLoader.csproj

* Update Program_Setup.cs

* Update Program_DbUpdates.cs

* Update Program_DbUpdates.cs

* Update ACE.DatLoader.Tests.csproj

* Update ACE.Database.Tests.csproj

* Update ACE.Database.csproj

* Update ACE.Server.Tests.csproj

* Update ACE.Server.csproj

* Update ACE.DatLoader.csproj

* Update ACE.Database.csproj

* Update ACE.Server.csproj

* Update EF packages to EFCore 6

Requires Database, Database.Tests and Adapater to target .NET6 framework

* Update ACE.Server.csproj

* Update ACE.Database.csproj

* Update Program_BinUpdates.cs

* Update AccountExtensions.cs

* update nugets

* Remove TimeZoneConverter

net6 includes built in functionality

* update csproj files

* Update ACE.Server.csproj
2022-07-13 12:30:32 -04:00

56 lines
1.4 KiB
C#

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace ACE.Server
{
public class WebClient: IDisposable
{
private readonly HttpClient httpClient;
public WebClient()
{
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("ACE.Server");
}
public async Task<string> GetStringFromURL(string url)
{
/* Initialize the request content
and
Send the Get
*/
var response = await httpClient.GetAsync(url);
//Check for error status
response.EnsureSuccessStatusCode();
//Get the response content
return await response.Content.ReadAsStringAsync();
}
public async Task DownloadFile(string url, string fileName)
{
/* Initialize the request content
and
Send the Get
*/
var response = await httpClient.GetAsync(url);
//Check for error status
response.EnsureSuccessStatusCode();
//Get the response content
using var fs = new FileStream(fileName, FileMode.CreateNew);
await response.Content.CopyToAsync(fs);
}
public void Dispose()
{
httpClient?.Dispose();
GC.SuppressFinalize(this);
}
}
}