Created
October 11, 2012 19:31
-
-
Save MorganPersson/3874937 to your computer and use it in GitHub Desktop.
Ignore SSL cert
This file contains hidden or 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
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