【问题标题】:Can ServiceStack JsonServiceClient send a get request to https w/self signed certificate?ServiceStack JsonServiceClient 可以向带有自签名证书的 https 发送获取请求吗?
【发布时间】:2013-05-18 03:57:52
【问题描述】:

我调用 JsonServiceClient 来序列化我的请求对象。我的服务器使用 https,我创建了一个自签名证书。

当客户端尝试连接并且服务器响应证书不受信任并且服务器的身份尚未验证时,似乎会引发异常。

在浏览器中,我可以忽略此消息。如何让 JsonService 客户端使用 https 和自签名证书?

【问题讨论】:

    标签: https ssl-certificate servicestack


    【解决方案1】:

    我认为this is a similar issue 正在发生的事情。您可以获取有关 ServerCertificateValidationCallback herehere 的更多信息。下面是一个测试,应该提供一个示例/模板来解决 JsonServiceClient 的“不可信”问题。显然,编写自己的证书验证存在一些风险。

    public void Test()
    {
        ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
        var client = new JsonServiceClient();
        var response = client.Post<string>("https://localhost/Secure/Route", new MySecureRequest());
    
        Assert.IsNotNull(response);
    }
    
    private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors)
    {
        //Do something to check the certificate is valid. 
        return false || cert.Subject.ToUpper().Contains("Something in Cert");
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 2012-11-21
      • 2019-12-25
      • 2014-05-05
      • 2020-04-24
      相关资源
      最近更新 更多