Cómo acceder URL con certificado no valido

By | 2010/07/09

Realizando un “robot” que accede un URL utilizando Net.HttpWebRequest sobre https que no tiene un certificado de una autoridad certificadora me tope con el siguiente error:
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Solución:

Sólo se debe agregar la siguiente línea.

ServicePointManager.ServerCertificateValidationCallback = Function(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As System.Net.Security.SslPolicyErrors) True

Es importante agregar los siguientes includes:

Imports System.Security.Cryptography.X509Certificates
Imports System.Net.Security.SslPolicyErrors

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.