File tree 3 files changed +21
-4
lines changed
3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ This repos contains tool classes in C# for multiple types of usage.
13
13
* WakeOnLan: Power on a device with it mac address.
14
14
15
15
* ` FrApp42.Web ` - [ Link] ( https://www.nuget.org/packages/FrApp42.Web )
16
- * Request: Make API request for any of your C# projects. ⚠️ * SOAP requests are not supported. * ⚠️
16
+ * Request: Make API request for any of your C# projects.
17
17
18
18
## Authors
19
19
* [ AnthoDingo] ( https://github.com )
Original file line number Diff line number Diff line change 2
2
using Newtonsoft . Json ;
3
3
using System . Net . Http . Headers ;
4
4
using System . Text ;
5
+ using System . Xml . Serialization ;
5
6
6
7
namespace FrApp42 . Web . API
7
8
{
@@ -392,8 +393,24 @@ private async Task<Result<T>> Process<T>(HttpRequestMessage request)
392
393
393
394
if ( response . IsSuccessStatusCode )
394
395
{
395
- Stream ContentResponse = await response . Content ? . ReadAsStreamAsync ( ) ;
396
- result . Value = await System . Text . Json . JsonSerializer . DeserializeAsync < T > ( ContentResponse ) ;
396
+ string MediaType = response . Content ? . Headers ? . ContentType ? . MediaType . ToLower ( ) ;
397
+ string ContentResponse = await response . Content ? . ReadAsStringAsync ( ) ;
398
+
399
+ switch ( true )
400
+ {
401
+ case bool b when ( MediaType . Contains ( "application/xml" ) ) :
402
+ XmlSerializer xmlSerializer = new ( typeof ( T ) ) ;
403
+ StringReader reader = new ( ContentResponse ) ;
404
+
405
+ result . Value = ( T ) xmlSerializer . Deserialize ( reader ) ;
406
+ break ;
407
+ case bool b when ( MediaType . Contains ( "application/json" ) ) :
408
+ result . Value = JsonConvert . DeserializeObject < T > ( ContentResponse ) ;
409
+ break ;
410
+ default :
411
+ result . Value = default ;
412
+ break ;
413
+ }
397
414
}
398
415
else
399
416
{
Original file line number Diff line number Diff line change 20
20
<PackageReadmeFile >README.md</PackageReadmeFile >
21
21
<Company >FrenchyApps42</Company >
22
22
<PackageIcon >logo.png</PackageIcon >
23
- <Version >1.1 .0</Version >
23
+ <Version >1.2 .0</Version >
24
24
</PropertyGroup >
25
25
26
26
<ItemGroup >
You can’t perform that action at this time.
0 commit comments