Ali*_*aza 5 mono xamarin.android xamarin.forms
向 HTTPS 服务器发出请求时,出现以下错误。请求适用于 HTTP。
{System.Net.WebException:错误:TrustFailure(身份验证失败,请参阅内部异常。) ---> System.Security.Authentication.AuthenticationException:身份验证失败,请参阅内部异常。---> Mono.Btls.MonoBtlsException: Ssl 错误:1000007d:SSL 例程:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
我已在 Android 设置中将 HTTPClientHandler 设置为 Android,将 TLS/SSL 实现设置为 Native TLD 1.2+。
这就是我使用的方式WebClient
,而不是只需要添加ServerCertificateValidationCallback
var uri = new UriBuilder("https://url/v3/0").Uri;
var client = new WebClient();
ServicePointManager.ServerCertificateValidationCallback = new
RemoteCertificateValidationCallback
(
delegate { return true; }
);
var content = client.DownloadString(uri);
Run Code Online (Sandbox Code Playgroud)
Ali*_*aza -3
我通过向 HttpWebRequest 对象添加ServerCertificateCustomValidationCallback属性解决了这个问题。
HttpWebRequest request = new HttpWebRequest(new Uri());
request.ServerCertificateCustomValidationCallback = delegate {return true;}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12677 次 |
最近记录: |