gpt4 book ai didi

xamarin.forms - Httpclient Xamarin Forms 调用在 Android 中不起作用

转载 作者:行者123 更新时间:2023-12-05 00:49:34 25 4
gpt4 key购买 nike

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

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

  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.

我尝试了许多解决方案,例如允许应用程序中的网络访问,确保所有需要的包都在那里,例如:
Microsoft.Bcl.Build
Microsoft.net.HTTP
Newtonsoft.json

这是我在 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 个主要错误:
[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+

enter image description here

关于xamarin.forms - Httpclient Xamarin Forms 调用在 Android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47480047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com