Replace WebClient with HttpClient to fix WebClient obsolete warning

This commit is contained in:
Ella Hathaway 2023-08-04 16:38:53 +00:00
parent 042639edf1
commit 383cb48f5a

View file

@ -15,6 +15,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using Task = Microsoft.Build.Utilities.Task; using Task = Microsoft.Build.Utilities.Task;
@ -87,8 +88,8 @@ namespace Microsoft.DotNet.SourceBuild.Tasks.UsageReport
/// <returns>The contents of the specified file.</returns> /// <returns>The contents of the specified file.</returns>
private string GetFileContents(string relativeFilePath, string commitSha) private string GetFileContents(string relativeFilePath, string commitSha)
{ {
WebClient client = new WebClient(); HttpClient client = new HttpClient();
var xmlString = client.DownloadString($"https://raw.githubusercontent.com/dotnet/source-build/{commitSha}/{relativeFilePath.Replace('\\', '/')}"); string xmlString = client.GetStringAsync($"https://raw.githubusercontent.com/dotnet/source-build/{commitSha}/{relativeFilePath.Replace('\\', '/')}").Result;
return xmlString; return xmlString;
} }