c# – Xamarin中的WebException,使用HttpClient
发布时间:2020-12-15 08:23:23 所属栏目:百科 来源:网络整理
导读:我正在学习如何在C#中使用xamarin,并且我有一个 Android应用程序来向外部API发出Web请求,并且我收到以下错误; System.Net.Http.HttpRequestException: An error occurred while sending the request --- System.Net.WebException: Error: SecureChannelFailu
我正在学习如何在C#中使用xamarin,并且我有一个
Android应用程序来向外部API发出Web请求,并且我收到以下错误;
System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed. 我的代码如下; public async Task<List<T>> GetList<T>(string url) { HttpClient client = new HttpClient(); var response = await client.GetAsync(new Uri(url)); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<List<T>>(content); } android中的MainClass调用核心类,它调用此服务类. 当API不使用HTTPS时,HttpClient请求会起作用,但每当我使用启用了HTTPS的API时,都会抛出此错误. 我也使用可移植类库来存储代码,因此无法使用HttpWebRequest进行Web请求. 我也尝试过; ServicePointManager.ServerCertificateValidationCallback += (o,certificate,chain,errors) => true; 和; System.Security.Cryptography.AesCryptoServiceProvider b = new System.Security.Cryptography.AesCryptoServiceProvider(); 在我的应用程序OnCreate类(android)中. 我还将HttpClient实现更改为AndroidClientHandler,同时将SSL / TLS实现更改为1.1.在模拟器和设备上尝试此操作. 有人有建议吗? 解决方法
试试这个:
打开Android项目属性 – > Android选项 – >高级 将HttpClient实现设置从Default切换到Android 似乎默认的Mono客户端处理程序因HTTPS而中断. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Postgresql 索引
- View类的XML属性、相关方法及说明
- 如何使用webclient UploadFile,C#中的UploadValues上传多个
- Swift:UserDefaults 协议( Swift 视角下的泛字符串类型 A
- postgresql – 在docker环境中重启postgres
- 实战DDD(Domain-Driven Design领域驱动设计:Evans DDD)
- 在C中传递char指针
- React Native未来导航者:react-navigation 使用详解
- Insecure directory in $ENV{PATH} while running with -T
- C++实现KMP算法