summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Pages/UriJsonSource.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Pages/UriJsonSource.cs')
-rw-r--r--Xamarin.Forms.Pages/UriJsonSource.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages/UriJsonSource.cs b/Xamarin.Forms.Pages/UriJsonSource.cs
new file mode 100644
index 00000000..d732e25c
--- /dev/null
+++ b/Xamarin.Forms.Pages/UriJsonSource.cs
@@ -0,0 +1,34 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+namespace Xamarin.Forms.Pages
+{
+ public class UriJsonSource : JsonSource
+ {
+ public static readonly BindableProperty UriProperty = BindableProperty.Create(nameof(Uri), typeof(Uri),
+ typeof(UriJsonSource), null);
+
+ public Uri Uri
+ {
+ get { return (Uri)GetValue(UriProperty); }
+ set { SetValue(UriProperty, value); }
+ }
+
+ public override async Task<string> GetJson()
+ {
+ var webClient = new HttpClient(new ModernHttpClient.NativeMessageHandler());
+ try
+ {
+ string json = await webClient.GetStringAsync(Uri);
+ return json;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+} \ No newline at end of file