代码之家  ›  专栏  ›  技术社区  ›  Praveen Rao Chavan.G

找不到证书路径的信任锚点[Osian.Forms]

  •  0
  • Praveen Rao Chavan.G  · 技术社区  · 4 年前

    当我试图 职位 使用 打开VPN

    注: 当我尝试在连接了Open VPN的平板电脑上使用swagger访问API时,API正在连接并运行良好,只是移动应用程序无法使用它。(在Xamarin应用程序中,我们得到了例外。

    代码:

    var uri = prepareLoginUri("/Login/Login");
    var body = new { username, password };
    var json = JsonConvert.SerializeObject(body);
    var content = new StringContent(json, Encoding.UTF8, "application/json");
    
    var response = await _client.PostAsync(uri, content);
    

    例外情况:

    java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
    

    已找到此异常的解决方案,但未修复问题:

    https://forums.xamarin.com/discussion/91782/trust-anchor-for-certification-path-not-found

    根据此链接中的建议,我在中添加了以下代码 主要活动cs

    HttpClientHandler clientHandler = new HttpClientHandler();
    clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
    _client = new HttpClient(clientHandler);
    

    这解决了异常,但现在我从API得到的响应是 404未找到 .

    StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent
    

    但在招摇撞骗中,API运行得非常好。

    0 回复  |  直到 4 年前
        1
  •  0
  •   Praveen Rao Chavan.G    4 年前

    解决方案

    我们需要一个SSL证书,但即使添加了一个,我们也遇到了这个问题,但 这与移动应用程序无关,问题在于SSL证书 我们没有正确配置证书,我们不得不添加中间体 在为HA代理生成.pem文件时使用证书。

    这个网站将我们的重点从移动应用程序转移到了服务器上。 https://www.digicert.com/help/

    它明确表示问题出在服务器上,以下是链接 这帮助我解决了这个问题。

    Trust Anchor not found for Android SSL Connection

        2
  •  -1
  •   Leo Zhu    4 年前

    试着放一个斜线( / )在最后 BaseAddress ,而且你不能放斜线( / )在相对URI的开头。比如:

    client.BaseAddress = new Uri("http://192.168.1.100:33435/ManageSystem/");
    var response = await client.GetAsync("Login/Login");