Created
January 23, 2016 05:23
-
-
Save arbo-hacker/151dca9f1bece51d7667 to your computer and use it in GitHub Desktop.
Consumir una URL a través de un Proxy usando Certificados
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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