.Net 6/7 提示SSL 证书验证错误(如:NotTimeValid等)参考解决方案

主要在于修改HttpClientHandler的内容,以使用HttpRequest为例:

```Csharp

// Generate request message

var httpRequest = new HttpRequestMessage(HttpMethod.Post, ApiUri);

httpRequest.Headers.Add("host", Host);

httpRequest.Content = new StringContent(Body,

null,

"application/json");

// Create new handler with ignoring all certificate errors

var handler = new HttpClientHandler();

handler.ClientCertificateOptions = ClientCertificateOption.Manual;

handler.ServerCertificateCustomValidationCallback =

(httpRequestMessage, cert, cetChain, policyErrors) =>

{

return true;

};

// Add handler into client

var client = new HttpClient(handler);

// Send reqeust

var response = client.Send(httpRequest);

Result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

```

你可能感兴趣的:(C#,.net,c#,https)