我正在学习如何在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.
Run Code Online (Sandbox Code Playgroud)
我的代码如下;
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);
}
Run Code Online (Sandbox Code Playgroud)
android中的MainClass调用核心类,它调用此服务类.
HttpClient的请求时,API不工作,不使用HTTPS,但每当我使用已启用HTTPS的API抛出此错误.
我也使用可移植类库来存储代码,因此无法使用HttpWebRequest进行Web请求.
我也尝试过;
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, …Run Code Online (Sandbox Code Playgroud)