diff --git a/README.md b/README.md index 4dd1784..249c5e0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This repos contains tool classes in C# for multiple types of usage. * WakeOnLan: Power on a device with it mac address. * `FrApp42.Web` - [Link](https://www.nuget.org/packages/FrApp42.Web) - * Request: Make API request for any of your C# projects. ⚠️ *SOAP requests are not supported.* ⚠️ + * Request: Make API request for any of your C# projects. ## Authors * [AnthoDingo](https://github.com) diff --git a/Web/API/Request.cs b/Web/API/Request.cs index f66fcb5..f9aa5cc 100644 --- a/Web/API/Request.cs +++ b/Web/API/Request.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using System.Net.Http.Headers; using System.Text; +using System.Xml.Serialization; namespace FrApp42.Web.API { @@ -392,8 +393,24 @@ private async Task> Process(HttpRequestMessage request) if (response.IsSuccessStatusCode) { - Stream ContentResponse = await response.Content?.ReadAsStreamAsync(); - result.Value = await System.Text.Json.JsonSerializer.DeserializeAsync(ContentResponse); + string MediaType = response.Content?.Headers?.ContentType?.MediaType.ToLower(); + string ContentResponse = await response.Content?.ReadAsStringAsync(); + + switch (true) + { + case bool b when (MediaType.Contains("application/xml")): + XmlSerializer xmlSerializer = new(typeof(T)); + StringReader reader = new(ContentResponse); + + result.Value = (T)xmlSerializer.Deserialize(reader); + break; + case bool b when (MediaType.Contains("application/json")): + result.Value = JsonConvert.DeserializeObject(ContentResponse); + break; + default: + result.Value = default; + break; + } } else { diff --git a/Web/Web.csproj b/Web/Web.csproj index cb3ca33..09b1be9 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -20,7 +20,7 @@ README.md FrenchyApps42 logo.png - 1.1.0 + 1.2.0