【问题标题】:How can I install certificate for "Visual studio emulator for android"'s emulator?如何为“Visual Studio emulator for android”的模拟器安装证书?
【发布时间】:2019-10-29 01:05:53
【问题描述】:

我正在处理需要调用 httpclient 以使用公司内部 https REST api 的 Xamarin 表单

不幸的是,它返回此错误

Javax.Net.Ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

我该如何解决这个问题?

【问题讨论】:

    标签: c# android xamarin certificate sslhandshakeexception


    【解决方案1】:

    要绕过认证验证,您可以:

    在 Android 构建选项中选择

    HttpClient Implementation: AndroidClientHandler
    SSL/TLS implementation: Default (Native TLS 1.2+)
    

    在 MainActivity.cs 添加这个

    ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;
    

    在 Httpclient init 中改变这个

    var httpClient = new HttpClient();
    

    var httpClient = new HttpClient(new System.Net.Http.HttpClientHandler());
    

    【讨论】:

    • 您好 Bruno,我找不到 Android 构建选项。这是否以 xamarin 形式提供,Visual Studio 2017?
    • 是的。右键单击android解决方案和选项
    • 感谢 bruno,我能够通过“右键单击 android 解决方案 >> 属性 >> Android 选项 >> 高级”找到它通过实施您的建议可以正常工作。再次感谢!
    • 嗨,DEN,很高兴我能帮上忙!
    • 不要把它留在生产代码中!它禁用证书链验证并启用中间人攻击。对于可以方便的开发(使用 Fiddler 来查看发生了什么),但在生产中,您不希望第三方嗅探您的流量。
    猜你喜欢
    • 2016-10-24
    • 1970-01-01
    • 2020-02-05
    • 2015-10-24
    • 2015-11-23
    • 2016-12-22
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多