Base
Base

Reputation: 1061

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?

Upvotes: 4

Views: 4295

Answers (1)

canton7
canton7

Reputation: 42225

You can use WebRequestHandler and its ServerCertificateValidationCallback property.

var handler = new WebRequestHandler()
{
    ServerCertificateValidationCallback = ....
};
var client = new HttpClient(handler);

Upvotes: 4

Related Questions