Httpclient Xamarin Forms调用在Android中不起作用 [英] Httpclient Xamarin Forms call not working in Android

查看:213
本文介绍了Httpclient Xamarin Forms调用在Android中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android物理设备中调试xamarin表单应用程序时,我遇到了一个奇怪的问题.

I am having a strange problem that occurs when debugging the xamarin forms app in android physical device.

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

The app goes to break mode and here is the output i receive:

  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.

我尝试了许多解决方案,例如允许在应用程序中访问网络,并确保所有必需的软件包都在其中,例如:

I tried many solutions such as allowing the network access in the app, made sure that the all needed packages are there such as:

Microsoft.Bcl.Build
Microsoft.net.HTTP
Newtonsoft.json

这是我的代码,在UWP中可以正常工作 var request = new HttpRequestMessage();

This is my code which works fine in UWP var request = new HttpRequestMessage();

    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();

我在设备日志中遇到2个主要错误:

I am getting 2 main errors in the device log:

[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实现.

Change the default SSL/TLS implementation in Xamarin.Android.

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

Go to Android Project settings->Android Options->Advanced->SSL/TLS implementation and set it to Native TLS 1.2+

这篇关于Httpclient Xamarin Forms调用在Android中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆