Can ServiceStack JsonServiceClient send a get request to https w/self signed certificate?

会有一股神秘感。 提交于 2020-01-14 13:54:07

问题


I making a call to get using JsonServiceClient to serialize my request object. My server is using https and I created a self signed certificate.

It would appear that an exception is thrown when the client tries to connect and the server responds that the certificate is not trusted and that the identity of the server has not been verified.

In a browser I can ignore this message. How can I get the JsonService client to work with https and a self signed certificate?


回答1:


I think this is a similar issue to what is happening. You can get more information on ServerCertificateValidationCallback here and here. Below is a test that should provide an example/template of getting past the 'not trusted' issue with JsonServiceClient. Obviously, there is some risk in writing your own certificate validation.

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");
}

Hope this helps.



来源:https://stackoverflow.com/questions/16616195/can-servicestack-jsonserviceclient-send-a-get-request-to-https-w-self-signed-cer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!