Xamarin.forms Httpclient Xamarin表单调用在Android中不起作用

Xamarin.forms Httpclient Xamarin表单调用在Android中不起作用,xamarin.forms,xamarin.android,httpclient,Xamarin.forms,Xamarin.android,Httpclient,在android物理设备上调试xamarin forms应用程序时,我遇到了一个奇怪的问题 应用程序进入中断模式,以下是我收到的输出: Mono.Android[0xd6be8960] -> System[0xd6be9680]: 14 11-24 23:44:44.098 I/Choreographer(18685): Skipped 930 frames! The application may be doing too much work on its main thr

在android物理设备上调试xamarin forms应用程序时,我遇到了一个奇怪的问题

应用程序进入中断模式,以下是我收到的输出:

  Mono.Android[0xd6be8960] -> System[0xd6be9680]: 14
    11-24 23:44:44.098 I/Choreographer(18685): Skipped 930 frames!  The application may be doing too much work on its main thread.
    Thread started: <Thread Pool> #8
    Thread started: <Thread Pool> #9
    11-24 23:44:44.807 D/Mono    (18685): Assembly Ref addref Mono.Security[0xc17989e0] -> System[0xd6be9680]: 15
    Thread started: <Thread Pool> #10
    An unhandled exception occured.
这是我的代码,在UWP中运行良好 var request=new-HttpRequestMessage()


编辑:设备日志中有两个主要错误:

[ERROR] FATAL UNHANDED EXCEPTION: System.Net.HttpRequestException:An error occurred while sending the request --> System.Net.WebException:Error:SecureChannelFailure(The authentication or decryption has failed)

更改Xamarin.Android中的默认SSL/TLS实现

转到Android项目设置->Android选项->高级->SSL/TLS实现,并将其设置为本机TLS 1.2+


在某些情况下,您需要将HttpClient实现更改为
AndroidClientHandler
,而不是
Default
,如下所示:


您是否尝试捕获异常?它只是进入中断模式,没有任何异常或解释。我在设备日志中收到两个主要错误:[错误]致命的未经处理的异常:System.Net.HttpRequestException:发送请求时出错-->System.Net.WebException:错误:SecureChannelFailure(身份验证或解密失败)感谢您的回复,我刚刚更改了上述选项,它起作用了。我的意思是httpclient实现,我还应该更改ssl/tls吗?对于我来说,如果我只是更改ssl/tls实现,那么它就起作用了。您可以更新您的答案,包括更改httpclient实现吗?然后,您的答案将是完美的,非常感谢help@Ali123如果我只是简单地将其切换到本机TLS1.2,我的方法实际上是有效的,但如果我同时更改httpclient实现,它就会中断。
    request.RequestUri = new Uri("https://jsonplaceholder.typicode.com/users");
    request.Method = HttpMethod.Get;

    request.Headers.Add("Accept", "application/json");
    var client = new HttpClient();
    HttpResponseMessage response = await client.SendAsync(request);
    HttpContent content = response.Content;
    var statusCode = response.StatusCode;
    var json = await content.ReadAsStringAsync();
[ERROR] FATAL UNHANDED EXCEPTION: System.Net.HttpRequestException:An error occurred while sending the request --> System.Net.WebException:Error:SecureChannelFailure(The authentication or decryption has failed)