c# – Xamarin表示PCL HttpClient在Android上抛出未处理的异常

我在Xamarin.Forms PCL中直接使用System.Net.Http.HttpClient.虽然它在Windows Phone上运行得非常好,但在Android上它会在GetAsync线上抛出未处理的异常.

有什么特定的平台我不见了吗?

var client = new HttpClient();
var response = await client.GetAsync(Constants.ProjectsUri); // this breaks
最佳答案
使用Native Android Client Handler

在Android Build Settings中,将HttpClient Implementation设置为使用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

转载注明原文:c# – Xamarin表示PCL HttpClient在Android上抛出未处理的异常 - 代码日志