问题
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