简体   繁体   中英

UWP client using HttpClient to communicate with .NET Web API, failed connection when SSL is enabled

I'm doing a project where I need to communicate with a Web API from a UWP-application.

I use HttpClient to do the job, and it works fine as long as the Web API is not using SSL. When I turn the SSL on, it just won't work. It works if I use some other client though, like browser/Wpf-application/console-application.

Probably you need to allow unsigned / self signed certificates. If so, you can do it the following way

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

var httpClient = new Windows.Web.Http.HttpClient(filter);

I hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM