Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling httpclient ssl verification, on request level, in net 4.6

Have a net 4.6.2 project (System.Net.Http 4.0). Have a httpclient connection that works fine when disable ssl verification, but its done using ServicePointManager.

Had some trouble finding how to disable this on a handler / client level in 4.6.

The following works:

ServicePointManager.ServerCertificateValidationCallback += (sender,certificate,chain,sslPolicyErrors) => true;
var handler = new HttpClientHandler();
var client = new HttpCLient(handler);

But when looking at msdn documentation, httpclienthandler does not seem to support ServerCertificateValidationCallback (or the 'dangerous' option) on 4.6 (its not avaible in code, and not ClientCertificates either).

So the question is how to disable this on client / handler / message level in 4.6?

like image 463
Base Avatar asked Sep 21 '25 00:09

Base


1 Answers

You can use WebRequestHandler and its ServerCertificateValidationCallback property.

var handler = new WebRequestHandler()
{
    ServerCertificateValidationCallback = ....
};
var client = new HttpClient(handler);
like image 114
canton7 Avatar answered Sep 22 '25 16:09

canton7