Skip to content

Instantly share code, notes, and snippets.

@MorganPersson
Created October 11, 2012 19:31
Show Gist options
  • Save MorganPersson/3874937 to your computer and use it in GitHub Desktop.
Save MorganPersson/3874937 to your computer and use it in GitHub Desktop.
Ignore SSL cert
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
namespace SslCertTest
{
[TestFixture]
public class IgnoreSslCertTest
{
private bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
// allow any certificate...
return true;
}
private string GetStuff()
{
var webRequest = (HttpWebRequest)WebRequest.Create("https://github.com/morganpersson");
webRequest.AllowAutoRedirect = true;
webRequest.Method = "GET";
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
using (Stream s = response.GetResponseStream())
{
using (var sr = new StreamReader(s))
{
return sr.ReadToEnd();
}
}
}
}
[Test]
public void Should_ignore_ssl_cert()
{
var s = GetStuff();
Assert.IsNotEmpty(s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment