servicestack,Https,Ssl Certificate,servicestack" /> servicestack,Https,Ssl Certificate,servicestack" />

ServiceStack JsonServiceClient是否可以通过自签名证书向https发送get请求?

ServiceStack JsonServiceClient是否可以通过自签名证书向https发送get请求?,https,ssl-certificate,servicestack,Https,Ssl Certificate,servicestack,我使用JsonServiceClient调用get来序列化我的请求对象。我的服务器正在使用https,我创建了一个自签名证书 当客户端尝试连接时,服务器响应证书不受信任且服务器的身份未经验证时,似乎会引发异常 在浏览器中,我可以忽略此消息。如何让JsonService客户端使用https和自签名证书?我想这是怎么回事。您可以获得有关ServerCertificateValidationCallback和的更多信息。下面是一个测试,它应该提供一个通过JsonServiceClient解决“不受信任

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

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

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

我想这是怎么回事。您可以获得有关ServerCertificateValidationCallback和的更多信息。下面是一个测试,它应该提供一个通过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");
}
公共无效测试()
{
ServicePointManager.ServerCertificateValidationCallback+=新的RemoteCertificateValidationCallback(ValidateRemoteCertificate);
var client=new JsonServiceClient();
var response=client.Post(“https://localhost/Secure/Route“,new MySecureRequest());
Assert.IsNotNull(响应);
}
私有静态bool ValidateRemoteCertificate(对象发送方、X509证书证书证书、X509链、SslPolicyErrors策略错误)
{
//采取措施检查证书是否有效。
返回false | | cert.Subject.ToUpper().Contains(“证书中的某物”);
}
希望这有帮助