【问题标题】:System.Net.WebException: Error: TrustFailure (Authentication failed, see inner exception.)System.Net.WebException:错误:TrustFailure(身份验证失败,请参阅内部异常。)
【发布时间】:2020-04-05 09:01:31
【问题描述】:

向 HTTPS 服务器发出请求时,出现以下错误。请求适用于 HTTP。

{System.Net.WebException:错误:TrustFailure(身份验证失败,请参阅内部异常。)---> System.Security.Authentication.AuthenticationException:身份验证失败,请参阅内部异常。 ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED

我已在 Android 设置中将 HTTPClientHandler 设置为 Android,并将 TLS/SSL 实施设置为 Native TLD 1.2+。

【问题讨论】:

  • 您使用的是自签名证书吗?
  • 我不知道它是什么。你能解释一下吗?
  • 自签名证书是未经证书颁发机构 (CA) 签名的证书。 :en.wikipedia.org/wiki/Self-signed_certificate
  • 我没有自签名任何证书。我实际上做了 SitePointManager hack 以允许 HTTPS 请求工作正常,但这次 System.Net.HTTPWebRequest 失败了。
  • 那么很可能您在服务器上缺少中间证书,它未配置为转发秘密 HTTPS 等...此外,如果您已正确安装和配置,为什么还要手动绕过验证过程证书?

标签: xamarin.forms xamarin.android mono


【解决方案1】:

这就是我使用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);

【讨论】:

    【解决方案2】:

    我通过像这样向 HttpWebRequest 对象添加 ServerCertificateCustomValidationCallback 属性解决了这个问题。

    HttpWebRequest request = new HttpWebRequest(new Uri());
    request.ServerCertificateCustomValidationCallback = delegate {return true;}
    

    【讨论】:

    • 感谢分享。不要忘记接受答案。
    • 此方法可能有效,但不安全。只是说..
    • 你确定HttpWebRequest这种构造函数?
    猜你喜欢
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 2014-07-08
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2016-04-10
    相关资源
    最近更新 更多