Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms PCL HttpClient throwing unhandled exception on Android

I am using System.Net.Http.HttpClient directly in the Xamarin.Forms PCL. While it runs absolutely fine on Windows Phone, on Android it throws an unhandled exception on the GetAsync line.

Is there something platform specific I'm missing?

var client = new HttpClient();
var response = await client.GetAsync(Constants.ProjectsUri); // this breaks
like image 397
EvilBeer Avatar asked Nov 10 '22 14:11

EvilBeer


1 Answers

Use the Native Android Client Handler

In the Android Build Settings, set HttpClient Implementation to use AndroidClientHandler.

Link to Xamarin Documentation

The AndroidClientHandler class was introduced in Xamarin.Android 6.1 to provide TLS 1.2 support to Xamarin.Android applications. This class uses the native java.net.URLConnection for all HTTP connections, allowing an HttpClient instance to use any network and encryption protocols available to Android.

enter image description here

like image 76
Brandon Minnick Avatar answered Nov 14 '22 22:11

Brandon Minnick