Tuesday, December 9, 2014

Call via HTTPClient to an SSL endpoint without a valid certificate

This isn't always a good idea, but sometimes you have to call an http endpoint using that has an SSL certificate that is not valid.  To allow the connection and disregard the certificate error, you can do something like the following:

 using (var client = new HttpClient(new HttpClientHandler()));  
   // this is the line that will ignore the certificate issues.  
   ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };  
   var response = taskClient.GetAsync(uri).Result;  

No comments:

Post a Comment