Windows Store Apps: The host name in the certificate is invalid or does not match

空扰寡人 提交于 2019-12-01 07:42:07

问题


in my windows 8.1 application, when I call a web service, I get the following exception:

The host name in the certificate is invalid or does not match

The code I use:

HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
HttpClient client = new HttpClient(filter);


HttpResponseMessage msg = await client.GetAsync(new Uri("[Service_URL]",UriKind.Absolute));
IRandomAccessStream randomAccessStream=(IRandomAccessStream)await msg.Content.ReadAsInputStreamAsync();

I'm using the HttpBaseProtocolFilter to bypass the errors that could be with the server's certificate, but it seems that it does not overcome the above exception.

Is there any workaround for this ?


回答1:


Try:

filter.IgnorableServerCertificateErrors.Add(
    ChainValidationResult.Untrusted |
    ChainValidationResult.InvalidName);

For more certificate ooptions take a look at ChainValitadionResult enumeration



来源:https://stackoverflow.com/questions/23868488/windows-store-apps-the-host-name-in-the-certificate-is-invalid-or-does-not-matc

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