1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
-
5
4
using System ;
6
5
using System . Collections . ObjectModel ;
7
6
using System . Net . Http ;
7
+ using System . Threading ;
8
+ using System . Threading . Tasks ;
8
9
using Microsoft . Toolkit . Parsers . Rss ;
9
10
using Windows . System ;
10
11
using Windows . UI . Xaml . Controls ;
@@ -18,7 +19,7 @@ public sealed partial class RssParserPage : Page
18
19
public RssParserPage ( )
19
20
{
20
21
this . InitializeComponent ( ) ;
21
- Loaded += ( s , e ) => ParseRSS ( ) ;
22
+ Loaded += ( s , e ) => ParseRSS ( ) ;
22
23
}
23
24
24
25
public string Url { get ; set ; } = "https://visualstudiomagazine.com/rss-feeds/news.aspx" ;
@@ -28,7 +29,11 @@ public async void ParseRSS()
28
29
string feed = null ;
29
30
RSSFeed . Clear ( ) ;
30
31
32
+ #if __WASM__
33
+ using ( var client = new HttpClient ( new CorsBypassHandler ( ) ) )
34
+ #else
31
35
using ( var client = new HttpClient ( ) )
36
+ #endif
32
37
{
33
38
try
34
39
{
@@ -66,5 +71,24 @@ private async void RSSList_SelectionChanged(object sender, SelectionChangedEvent
66
71
67
72
RSSList . SelectedItem = null ;
68
73
}
74
+
75
+ #if __WASM__
76
+ public class CorsBypassHandler : DelegatingHandler
77
+ {
78
+ public CorsBypassHandler ( )
79
+ {
80
+ InnerHandler = new HttpClientHandler ( ) ;
81
+ }
82
+
83
+ protected override Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
84
+ {
85
+ var builder = new UriBuilder ( request . RequestUri ) ;
86
+ builder . Host = "cors-anywhere.herokuapp.com" ;
87
+ builder . Path = request . RequestUri . Host + builder . Path ;
88
+
89
+ return base . SendAsync ( new HttpRequestMessage ( request . Method , builder . Uri ) , cancellationToken ) ;
90
+ }
91
+ }
92
+ #endif
69
93
}
70
94
}
0 commit comments