添加System.Net.Http.WebRequest的引用
new一个WebRequestHandler对象
将WebRequestHandler对象的ServerCertificateValidationCallback设为delegate { return true; };
使用该WebRequestHandler对象new HttpClient对象
使用该HttpClient对象即可
相关代码如下:
var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return true; }; var httpClient = new HttpClient(handler); httpClient.BaseAddress = new Uri("https://www.baidu.com"); var response = await httpClient.GetAsync("https://www.baidu.com");