Replace WebClient with HttpClient

This commit is contained in:
Raymond 2021-08-09 11:04:26 -04:00
parent d23ed9020a
commit 965f2142ff
2 changed files with 9 additions and 9 deletions

View file

@ -359,16 +359,17 @@ namespace Dalamud.Plugin.Internal
// ignored, since the plugin may be loaded already
}
using var client = new WebClient();
var tempZip = new FileInfo(Path.GetTempFileName());
try
{
Log.Debug($"Downloading plugin to {tempZip} from {downloadUrl}");
client.DownloadFile(downloadUrl, tempZip.FullName);
using var client = new HttpClient();
var response = client.GetAsync(downloadUrl).Result;
using var fs = new FileStream(tempZip.FullName, FileMode.CreateNew);
response.Content.CopyToAsync(fs).GetAwaiter().GetResult();
}
catch (WebException ex)
catch (HttpRequestException ex)
{
Log.Error(ex, $"Download of plugin {repoManifest.Name} failed unexpectedly.");
throw;

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Dalamud.Logging.Internal;
@ -74,11 +74,10 @@ namespace Dalamud.Plugin.Internal
return Task.Run(() =>
{
using var client = new WebClient();
Log.Information($"Fetching repo: {this.PluginMasterUrl}");
var data = client.DownloadString(this.PluginMasterUrl);
using var client = new HttpClient();
using var response = client.GetAsync(this.PluginMasterUrl).Result;
var data = response.Content.ReadAsStringAsync().Result;
var pluginMaster = JsonConvert.DeserializeObject<List<RemotePluginManifest>>(data);
pluginMaster.Sort((pm1, pm2) => pm1.Name.CompareTo(pm2.Name));