Accepting invalid SSL certificates using WinRT

吃可爱长大的小学妹 提交于 2019-12-12 08:02:57

问题


There are scenarios where you want your application to accept invalid SSL certificates (testing environment/ self signed certificates etc).

In the .NET world one would use the ServerCertificateValidationCallback class to do so. Unfortunately the class doesn't exist in a WinRT context.

I need to consume a Web API using WinRT which is hosted on a server without a valid ssl certificate.

How do you accept invalid ssl certificates in WinRT using the HttpClient class or any other appropriate class.

Any help or alternatives would much appreciated.


回答1:


in silverlight, it wasn't allowed. I haven't seen anything that says it's allowed in winrt.




回答2:


The following code worked for me for the debugging scenario:

var filter = new HttpBaseProtocolFilter();
#if DEBUG
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
#endif
using (var httpClient = new HttpClient(filter)) {
    ...
}


来源:https://stackoverflow.com/questions/11955590/accepting-invalid-ssl-certificates-using-winrt

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