CnCNet / xna-cncnet-client

XNA / MonoGame based client for playing classic Command & Conquer games both online and offline with a CnCNet game spawner.
Other
223 stars 86 forks source link

Replace WebClient and WebRequest to HttpClient #515

Open frg2089 opened 4 months ago

frg2089 commented 4 months ago

The following APIs are marked as obsolete, starting in .NET 6. Using them in code generates warning SYSLIB0014 at compile time.

SYSLIB0014 - Microsoft Learn

Add System.Net.Http.Json package to polyfill GetFromJsonAsync methods.

like this:

https://github.com/CnCNet/xna-cncnet-client/blob/f89c8fcdb0008bac7b7e205d561544e000340373/DXMainClient/Domain/Multiplayer/CnCNet/CnCNetPlayerCountTask.cs#L53-L80

// TODO: Cached it!
// See https://learn.microsoft.com/dotnet/api/system.net.http.httpclient.-ctor?view=net-8.0#remarks
HttpClient client = new();
// TODO: make it async.
var infos = client.GetFromJsonAsync<Dictionary<string, int>>("http://api.cncnet.org/status").Result;
if (!infos.TryGetValue(cncnetLiveStatusIdentifier, out int numGames))
    numGames = -1;

return numGames;

TODO