简体   繁体   English

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

[英]Xamarin Forms PCL HttpClient throwing unhandled exception on Android

I am using System.Net.Http.HttpClient directly in the Xamarin.Forms PCL. 我在Xamarin.Forms PCL中直接使用System.Net.Http.HttpClient。 While it runs absolutely fine on Windows Phone, on Android it throws an unhandled exception on the GetAsync line. 虽然它在Windows Phone上运行得非常好,但在Android上它会在GetAsync线上抛出未处理的异常。

Is there something platform specific I'm missing? 有什么特定的平台我不见了吗?

var client = new HttpClient();
var response = await client.GetAsync(Constants.ProjectsUri); // this breaks

Use the Native Android Client Handler 使用Native Android Client Handler

In the Android Build Settings, set HttpClient Implementation to use AndroidClientHandler . 在Android Build Settings中,将HttpClient Implementation设置为使用AndroidClientHandler

Link to Xamarin Documentation 链接到Xamarin文档

The AndroidClientHandler class was introduced in Xamarin.Android 6.1 to provide TLS 1.2 support to Xamarin.Android applications. AndroidClientHandler类在Xamarin.Android 6.1中引入,为Xamarin.Android应用程序提供TLS 1.2支持。 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. 此类对所有HTTP连接使用本机java.net.URLConnection,允许HttpClient实例使用Android可用的任何网络和加密协议。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM