Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Consumir una URL a través de un Proxy usando Certificados
//Hay q forzar a aceptar el certificado, ya que
//el nombre que se utiliza en la solicitud HTTP no
//coincide con el nombre del servidor que se emite con el certificado SSL
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
WebProxy proxy = new WebProxy("http://servidorconproxy:8080/",true);
proxy.Credentials = new NetworkCredential("user","password");
System.Net.HttpWebRequest hr=System.Net.WebRequest.Create("https://www.unapagina.com") as System.Net.HttpWebRequest ;
hr.Proxy = proxy;
HttpWebResponse o=hr.GetResponse() as HttpWebResponse;
Stream stream= o.GetResponseStream();
XmlDocument xD= new XmlDocument();
xD.Load(stream);
XmlNode n;
n = xD.SelectSingleNode("InvoiceConfirmationRS");
object aver=n;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace WebApplication1 {
/// <summary>
/// Fuerza a aceptar Certificados cuya url es distinta de la pagina que se esta viendo
/// </summary>
//Hay q forzar a aceptar el certificado, ya que
//el nombre que se utiliza en la solicitud HTTP no
//coincide con el nombre del servidor que se emite con el certificado SSL
public class MyPolicy : ICertificatePolicy {
public bool CheckValidationResult(ServicePoint srvPoint , X509Certificate certificate , WebRequest request , int certificateProblem) {
//Return True to force the certificate to be accepted.
return true;
}
// end CheckValidationResult
} //class MyPolicy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.